Springboot項目通過Nginx配置後缺少Nginx定義攔截路徑

Springboot項目通過Nginx配置後缺少Nginx定義路徑

說明:

以下項目是springboot項目,但是未使用前後端分離,所有的靜態文件路徑及後端請求都會缺少Nginx中配置的轉發攔截的路徑,具體問題情境如下所示:

1. 錯誤演示

1.1. 後端請求缺少攔截路徑

 

1.2. 靜態資源缺少攔截路徑

 

1.3. Nginx配置:

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
keepalive_timeout  65;
    server {
        listen       80;
        server_name  IP地址;
		proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $host:$server_port;  
location /tipo/ { 	
		   proxy_pass http://IP地址:6060/; 
		   proxy_connect_timeout 60s;
		   proxy_read_timeout 60s;
		   proxy_send_timeout 60s; 		 
	   }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        } 
    }
		

2.1. Springboot添加配置2. 解決辦法:

添加以下配置後,所以的請求都會加上tipo路徑。

配置如下:

server:
  servlet:
    context-path: /tipo/

注意:

  頁面中引入的靜態文件不能用基路徑,需要用相對路徑

2.2. Nginx修改後的配置

如下:

location /tipo/ { 	
		  proxy_pass http://ip路徑:6060/tipo/; 
		  proxy_connect_timeout 60s;
		  proxy_read_timeout 60s;
		  proxy_send_timeout 60s; 		 
		 
	}

因爲在該服務器上還使用了其他服務,本人的配置如下,各位使用Nginx配置時請根據自身情況進行配置。

以上爲本篇博客的主要內容,若對以上有所疑問的可以留言探討,轉載請說明出處,本人博客地址:https://www.cnblogs.com/chenyuanbo/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章