天天看點

nginx+tomcat配置域名,域名通路tomcat項目,vue通路nginx405解決

nginx+tomcat配置域名,域名通路tomcat項目

tomcat配置檔案不用改,可以預設端口8080

nginx配置檔案需要改如下:加反向代理

server
    {
        listen 80;

        server_name  mall.tianxiabox.com;#通路tomcat服務的域名
        #access_log  logs/host.access.log  main;
        location / {
             proxy_pass http://127.0.0.1:8080;#tomcat服務的位址
             root   html;
             index  index.html index.htm;
             client_max_body_size 20M;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            proxy_set_header Host mall.tianxiabox.com;
            proxy_set_header X-Forwarded-For "$http_x_forwarded_for, $remote_addr";
        }

 					location ~ .*\.(jpg|png|jpeg|js|css)$ {
             proxy_pass http://127.0.0.1:8080;
         }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
           

以上這樣nginx反向代理即可實作使用mall.tianxiabox/項目

域名形式通路項目

VUE通路阿裡雲伺服器nginx,打包成靜态檔案後不能405,method not allow的問題解決:

比如阿裡雲端口:46.45.123.113

vue代碼運作起來通路這個公網端口沒問題,然後打包成靜态檔案後就不能通路了,解決辦法配置nginx代理:

server {
    listen       80;                        # 監聽端口
    server_name mobile.tianxiabox.com;    # 站點域名
    index index.html index.htm ;   # 預設導航頁
    

    location /api/{   #vue端使用mobile.tianxiabox.com/api/接口名來通路服務端接口
        rewrite  ^.+api/?(.*)$ /$1 break;
        include  uwsgi_params;
        proxy_pass http://127.0.0.1:8099;   #服務端用的springboot,端口8099
    }
    
    location /mallapi/{  		#vue端使用mobile.tianxiabox.com/mallapi/接口名來通路服務别的項目端接口
        rewrite  ^.+mallapi/?(.*)$ /$1 break;
        include  uwsgi_params;
        proxy_pass http://127.0.0.1:8089;
    }
 
    location / {    #vue端靜态代碼路徑
        root  /home/wwwroot/userbox/dist;
        try_files $uri $uri /index.html;
        index index.html index.htm;
    }

    access_log  /home/wwwlogs/box-access.log;
   
}
           

繼續閱讀