关于nginx的总结
为了让接口在本地跑起来,公司需要配置nginx
这里有三个地方需要配置
1.C:\Windows\System32\drivers\etc\hosts
# localhost name resolution is handled within DNS itself. 127.0.0.1 xx.3tlife.cn # ::1 localhost #192.168.10.53 gitlab.3tlife.cn
2.nginx文件下的conf/nginx.conf
server { listen 80; server_name xx.3tlife.cn; location ^~ /api/ { proxy_pass http://192.168.10.79:7002/3t-mobile-user/; 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_set_header X-Forwarded-Proto $scheme; }
}
如果又有一个项目需要在本地跑起来
只需要增加,然后修改这两处,proxy_pass是要和运维说,nursing-gw 是接口比如接口是:/nursing-gw/user/1
location ^~ /nursing-gw/ { proxy_pass http://192.168.10.38:30600/; 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_set_header X-Forwarded-Proto $scheme; } location / { root html; index index.html index.htm; }
3.html中接口的url url要改成 var URL = 'http://xx.3tlife.cn/api/app' url: URL + '/nursing-gw/user/1' 把接口前面部分的接口名称改掉
4.在本地跑起来的网页的网址也要改掉:
原:file:///C:/Users/Administrator/Desktop/nginx-1.13.8/html/activity/index.html
后:http://xx.3tlife.cn/activity/index.html