nginx 小白求助 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Jakesoft
V2EX    NGINX

nginx 小白求助

  •  
  •   Jakesoft
    Jaggle 2016-04-15 14:43:25 +08:00 2968 次点击
    这是一个创建于 3521 天前的主题,其中的信息可能已经有所发展或是发生改变。

    求助: 不完全配置如下

    server{ listen 80; server_name server; location / { proxy_pass http://my.proxy.server; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 
    server { listen 8080; server_name 127.0.0.1; index index.php index.html index.htm; root /www; #pathinfo 模式支持 include vhosts/rewrite/default.conf; allow 127.0.0.1; deny all; } 
    upstream my.proxy.server{ server 127.0.0.1:8080; } 

    问题如下:

    一个静态文件,路径是 http://server/a/index,

    为什么访问 http://server/a 时跳到

    http://server:8080/a/

    而我不想把8080端口暴露出来,求教哪里出问题了?

    6 条回复    2016-04-15 16:50:19 +08:00
    Busy
        1
    Busy  
       2016-04-15 14:54:19 +08:00
    proxy_pass http://my.proxy.server:8080;
    lhbc
        2
    lhbc  
       2016-04-15 15:21:28 +08:00
    proxy_redirect http://localhost:8080/ http://$host;
    kookerjp
        3
    kookerjp  
       2016-04-15 15:32:44 +08:00
    http {
    port_in_redirect off;
    Jakesoft
        4
    Jakesoft  
    OP
       2016-04-15 15:57:10 +08:00
    @kookerjp 你这个方法可以,但是我的网站使用了 https,导致 https://server/a 301 到 http://server/a/,然后继续 301 到 https://server/a/,第二个 301 是我自己配置的:

    rewrite ^(.*)$ https://$host$1 permanent;

    关键是第一个 301 是怎么来的,难道反向代理一个静态文件会直接 301 跳转吗?
    Busy
        5
    Busy  
    2016-04-15 16:45:50 +08:00
    试试这样
    server {
    listen 80;
    server_name domain;
    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:8080;
    }
    }

    然后给 8080 端口的也写个 server
    server {
    listen 8080;
    server_name 127.0.0.1;

    location / {
    root /www;
    index index.php index.html index.htm;
    }
    }

    如果不行,则在 8080 的 server 中加 port_in_redirect off;
    server {
    listen 8080;
    server_name 127.0.0.1;
    port_in_redirect off ;

    location / {
    root /www;
    index index.php index.html index.htm;
    }
    }
    Busy
        6
    Busy  
       2016-04-15 16:50:19 +08:00
    443 端口应该这样

    80 端口跳到 443 ,用 443 端口的 server 去 proxy_pass http://127.0.0.1:8080;
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     902 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 22:58 PVG 06:58 LAX 14:58 JFK 17:58
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86