背景:

若依移动端的项目:整合了uview开源ui框架

部署流程

1. 配置后端请求接口基本路径地址:

2. 打包复制到nginx下:nginx/htm/newxss, (newxss目录手动创建)

3.在nginx上配置了站点与api代理 

Nginx配置

安装个稳定版本的:nginx-1.24.0

部署配置:

1.增加了网站:8083端口的, 网站目录在nginx/html下的子目录:newxss

之后就可以愉快的使用这个端口了。如下,使用他来指向一个新网站项目。

2. 配置跨域转发   /apixss

3.多个后台服务器的话,增加跨域配置如 /secondapi, 把它们写在8083端口的server{}对象里。

 location /secondapi {
                  # 后端的真实接口 http://10087whhkj.com/webapi
                  proxy_pass http://10087.whhkj.com/webapi;

            }

4. 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;
        server_name  192.168.10.101;
        # 配置根目录的地址是以 nginx 下的 html 文件夹为根目录来查找的
        root html;
        location / {
            root html/newxss;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

         # 关键步骤 http://192.168.10.101/apixss/ 开头的请求都会转发到下面proxy_pass
          location /apixss {
               # 后端的真实接口 http://10086.whhkj.com/webapi
               proxy_pass http://10086.whhkj.com/webapi;
            }
        }
  
}

5. 重启nginx:   nginx -s reload,就可以正常访问了。

网域运行: 

遇到404,是跨域路径没匹配到,405是匹配到路径,但是路径错。

部署到阿里云nginx

阿里云 linux 的nginx 配置uni-app的前端项目vue_Lan.W的博客-CSDN博客


一直404,405 排除:

1. 服务器中,有两个nginx,有可能造成跨域失效。

2. 多次改配置,从网上拷贝一些不适合的配置导致,接口,路径什么都对上就是404,405,那么,把整个nginx.conf删除,重新拷贝一个干净的过来,再做配置。

Logo

快速构建 Web 应用程序

更多推荐