Solve nginx deployment front-end post request 405 not allowed

Problem After deploying the front-end for the first time, after deploying the dist file generated by Vue to nginx, when entering the page and post requesting data query, 405 not allowed appears. After checking, it is found that nginx static resource access does not support post requests.
insert image description here

solution

       location / {
    
    
            root  /usr/local/dist;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
            error_page 405 =200 @405;  #405页面处理
}

        #加入下面代码
       location @405 {
    
    
             proxy_set_header Host $host; 
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
             #ip为后端服务地址
             proxy_pass http://192.168.3.129:8081$request_uri ;
}

Guess you like

Origin blog.csdn.net/qq_46645840/article/details/126644251