1. 安装 Homebrew
1.1. 官网安装
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- PASSWORD(电脑的密码)
- ENTER 继续
1.2. 安装成功
$ brew -v
注意:安装过程中最好打开
vpn,不然失败的概率很高。
1.3. brew update -- 转 2.2
2. 安装配置 Nginx 反向代理
2.1. 安装 nginx
$ brew install nginx
注意 报错,需要
brew update
2.2. brew update
$ brew update
注意 根据报错,查阅资料,需要执行
brew upgrade
2.3. brew upgrade
$ cd /usr/local/Homebrew/Library/Taps/homebrew
# 删除 homebrew-core 文件夹
$ rm -rf homebrew-core
$ brew upgrade
2.4. 再次安装 nginx
$ brew install nginx
$ nginx -v
3. Nginx的启动及配置相关文件
3.1. 配置 nginx
$ cd /usr/local/etc/nginx
$ vim nginx.conf
3.2. 启动 nginx
$ brew services start nginx
# 重新启动
$ brew services restart nginx
浏览器访问 http://localhost:8080/
,出现如下界面,则启动成功。
【注意】 启动端口在
3.1中的 nginx.conf 文件中可配置。
3.3 停止nginx
# 停止
$ brew services stop nginx
4. 把 dist 部署到 Nginx 上
nginx.conf文件
- 默认路径
/usr/local/etc/nginx/nginx.conf
- 配置详情
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include servers/*;
}
5. nginx单域名配置多项目
nginx.conf文件中出现include servers/*,则可以在servers文件夹中配置单独项目的server,如下:
# proxy_nginx_1.conf
server {
# 服务器名称和别名
server_name proxy_nginx_1 alias www.xxx.com;
# 端口号
listen 8088;
# 站点 WebSite 目录的绝对路径
root /user/xxx/xxx/manage/dist; # 打包后的dist文件夹的路径
# 服务包名
location ~* ^/(auth|admin){
proxy_pass http://172.16.10.178:9999;
proxy_connect_timeout 3600s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
- 访问
nginx配置后的服务