nginx
Mac
- 安装Homebrew(若已安装,可以跳过)
1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 使用brew安装nginx
1
brew install nginx
- 启动nginx
1
brew services start nginx
- 将nginx设置为开机自启
1
launchctl start ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
- 设置nginx通用配置
1
vim /usr/local/etc/nginx/servers/fe_jiatt_qa.conf
- 粘贴如下配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17server {
listen 80;
server_name *.qa.jiatt.com;
if ($http_host ~* "^(.*?)\.qa\.jiatt\.com$") {
set $domain $1;
}
location / {
proxy_pass http://127.0.0.1:$1;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
} - 重载/重启nginx
1
2
3nginx -t # 检查配置是否正确
nginx -s reload # 重载nginx(2、3行任选一个命令执行)
brew services restart nginx # brew重启nginx(2、3行任选一个命令执行) - 根据本地端口配置hosts,如
1
2
3
4
5
6
7
8
9# 本地启了个 3000、3001、3002 项目,不需要更改nginx配置,直接添加三个host,如
sudo vim /etc/hosts
# 添加三行
127.0.0.1 3000.qa.jiatt.com
127.0.0.1 3001.qa.jiatt.com
127.0.0.1 3002.qa.jiatt.com - 直接访问试试,后面有新端口直接配host就行
Centos7+/Ubuntu18+
- 安装nginx
1
2yum install -y nginx # centos
apt install -y nginx # ubuntu - 启动
1
2systemctl start nginx # 启动nginx
systemctl enable nginx # 开机自启 - 剩余配置参考上方【Mac】5~9 配置部分,注意二则配置文件保存路径的区分,一般配置文件路径参考:Windows(win10+)
1
vim /etc/nginx/conf.d/fe_jiatt_qa.conf
直接在Windows应用商店下载一个Ubuntu,作为win的子系统,参考上面方式即可。
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!