- brew install nginx //安装nginx
- cd /usr/local/etc/nginx/
- ls -al 查看所有nginx 目录下文件
- cd servers/
- touch server //创建文件(名字随意起)
- open . // 打开当前文件
- 如修改完server配置文件时需执行如下俩命令 相当于重启nginx
- nginx -t 检查语法是否正确
- nginx -s reload 启动nginx
- 创建的server内容如下
server {
listen 80;//http 端口80;https 端口 443
server_name aa.com; //服务器域名
root /Users/steven/Documents/jane/project/dist; //项目打包之后生成的根目录查看根目录路径:pwd
location / {
try_files $uri $uri/ @router;
index index.html index.htm;
}
location /napi/ {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:1235/;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
网友评论