zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    环求解点值
    汉诺塔(记录每种路径次数)
    快速排序
    选择排序
    冒泡排序
    桶排序
    异或后最大lowerbit
    计数三角形
    nico和niconiconi
    提高程序设计能力的一般方法
  • 原文地址:https://www.cnblogs.com/chenyuanbo/p/13848462.html
Copyright © 2011-2022 走看看