mhtt
V2EX  ›  问与答

请教一个 nginx 的规则写法

  •  
  •   mhtt · Oct 9, 2016 · 1354 views
    This topic created in 3543 days ago, the information mentioned may be changed or developed.

    一个 nodejs 的程序, node app.js 后的访问地址是 http://127.0.0.1:6000,下面是我的 nginx 的配置

    server {
    listen 80;
            server_name domain.com;
            location / {
                    proxy_pass https://127.0.0.1:6000;
            }
    }
    

    可以通过 domain.com 直接访问该程序,正常,但我现在想通过 domain.com/blog 这样的方式访问这个 nodejs 程序,而 domain.com 则访问指定的地址, nginx 改成如下

    server {
    listen 80;
            server_name domain.com;
            root /sites;
            index index.html index.htm;
    }
    

    那么 domain.com/blog 该如何配置呢?

    是不对的,请教正确的方式是?

    4 replies    2016-10-09 15:42:05 +08:00
    jackysc
        1
    jackysc  
       Oct 9, 2016
    server {
    listen 80;
    server_name domain.com;
    root /sites;
    index index.html index.htm;
    location /blog {
    proxy_pass https://127.0.0.1:6000;
    }
    }
    ryd994
        2
    ryd994  
       Oct 9, 2016 via Android
    @jackysc 不,要 proxy_pass https://127.0.0.1:6000/; 最后的斜杠会替换 /blog/路径
    而且要正常工作的话,可能还需要 http_sub 替换引用的链接
    yangg
        3
    yangg  
       Oct 9, 2016
    try_files

    server {
    listen 443 ssl http2;
    server_name www.uedsky.com;
    include ssl.conf;

    location / {
    root /var/www/uedsky.www/current/public;
    try_files $uri $uri/index.html @site;
    # expires 30d;
    }
    location @site {
    proxy_pass http://127.0.0.1:3333;
    proxy_set_header Host $http_host;
    }
    }
    yangg
        4
    yangg  
       Oct 9, 2016
    没看清要求,忽略。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5409 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 243ms · UTC 05:57 · PVG 13:57 · LAX 22:57 · JFK 01:57
    ♥ Do have faith in what you're doing.