V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
ijkm1234
V2EX  ›  NGINX

nginx 中在 proxy_pass 的 url 后面加/的问题

  •  
  •   ijkm1234 · 2018-09-06 11:18:59 +08:00 · 2729 次点击
    这是一个创建于 2270 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我希望用 /auth/api/values 访问 /api/values,但是按照下面配置是返回的是 nginx 的默认界面

    server {                                                                            
         listen 80;
         server_name xxx.xxx.xxx.xxx;
         location ^~ /auth/ {
             proxy_pass         http://localhost:5000/;
             proxy_http_version 1.1;
             proxy_set_header   Upgrade $http_upgrade;
             proxy_set_header   Connection keep-alive;
             proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
         }
     }
    

    但按照下面设置并且用 /auth/values 可以正常访问 api

    server {                                                                            
         listen 80;
         server_name xxx.xxx.xxx.xxx;
         location ^~ /auth/ {
             proxy_pass         http://localhost:5000/api/;
             proxy_http_version 1.1;
             proxy_set_header   Upgrade $http_upgrade;
             proxy_set_header   Connection keep-alive;
             proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
         }
     }
    

    按道理这两个方法不都是应该访问 /api/values 吗?
    nginx.conf 如下

    user www-data;                                                                                  
      2 worker_processes auto;
      3 pid /run/nginx.pid;
      4 
      5 events {
      6         worker_connections 768;
      7         # multi_accept on;
      8 }
      9 
     10 http {
     11 
     12         ##
     13         # Basic Settings
     14         ##
     15 
     16         sendfile on;
     17         tcp_nopush on;
     18         tcp_nodelay on;
     19         keepalive_timeout 65;
     20         types_hash_max_size 2048;
     21         # server_tokens off;
     22 
     23         # server_names_hash_bucket_size 64;
     24         # server_name_in_redirect off;
     25 
     26         include /etc/nginx/mime.types;
     27         default_type application/octet-stream;
     28
     29         ##
     30         # SSL Settings
     31         ##
     32 
     33         ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
     34         ssl_prefer_server_ciphers on;
     35 
     36         ##
     37         # Logging Settings
     38         ##
     39 
     40         access_log /var/log/nginx/access.log;
     41         error_log /var/log/nginx/error.log;
     42 
     43         ##
     44         # Gzip Settings
     45         ##
     46 
     47         gzip on;
     48         gzip_disable "msie6";
     49 
     50         # gzip_vary on;
     51         # gzip_proxied any;
     52         # gzip_comp_level 6;
     53    		# gzip_buffers 16 8k;
     54         # gzip_http_version 1.1;
     55         # gzip_types text/plain text/css application/json application/javascript text/xml applic    ation/xml application/xml+rss text/javascript;
     56 
     57         ##
     58         # Virtual Host Configs
     59         ##
     60 
     61         include /etc/nginx/conf.d/*.conf;
     62         #include /etc/nginx/sites-enabled/*;
     63 }
    
    Acoffice
        1
    Acoffice  
       2018-09-06 12:59:59 +08:00 via Android
    就是加 / 和不加的区别。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   909 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:06 · PVG 06:06 · LAX 14:06 · JFK 17:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.