若依移动端的项目:整合了uview开源ui框架,
配置后端请求接口基本路径地址:

打包复现到nginx下:

安装个稳定版本的:nginx-1.24.0
部署配置:
增加了网站:8083端口的, 网站目录在nginx/html下的子目录:newxss
配置跨域转发 /apixss,
多个后台服务器的话,增加跨域配置如 /secondapi, 把它们写在8083端口的server{}对象里。
location /secondapi {
# 后端的真实接口 http://10086.whhkj.com/webapi
proxy_pass http://10087.whhkj.com/webapi;}
nginx.conf
#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}server {# 监听的端口号listen       8083;# 服务名称 生产环境要修改成 公网ip 如 47.105.134.120server_name  192.168.10.101;# 配置根目录的地址是以 nginx 下的 html 文件夹为根目录来查找的root html;# 配置默认的主页显示 比如 47.105.134.120:8080 显示的 index 页面location / {root html/newxss;index  index.html index.htm;try_files $uri $uri/ /index.html;}# 关键步骤,这里表示将所有的 http://192.168.7.8:8888/teamnote/api/ 开头的请求都转发到下面 proxy_pass 指定的链接中# http://192.168.10.101/xss/ 开头的请求都会转发到下面proxy_passlocation /apixss {# 后端的真实接口 http://10086.whhkj.com/webapiproxy_pass http://10086.whhkj.com/webapi;}location /secondapi {# 后端的真实接口 http://10086.whhkj.com/webapiproxy_pass http://10087.whhkj.com/webapi;}}}
重启nginx: nginx -s reload,就可以正常访问了。
遇到404,是跨域路径没匹配到,405是匹配到路径,但是路径错。
一直404,405 排除:
1. 服务器中,有两个nginx,有可能造成跨域失效。
2. 多次改配置,从网上拷贝一些不适合的配置导致,接口,路径什么都对上就是404,405,那么,把整个nginx.conf删除,重新拷贝一个干净的过来,再做配置。