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

NGINX 做了反代隐藏不了端口什么原因?

  •  
  •   jtnetcc · 2019-05-12 20:27:14 +08:00 · 3754 次点击
    这是一个创建于 1781 天前的主题,其中的信息可能已经有所发展或是发生改变。

    环境是用 oneinstck 做的

    域名 10.0531.tw 不正常 10.0531.tw:5000 正常

    大神们帮我看看应该怎么处理才能正常不需要加端口访问,谢谢。

    配置文件:

    server {

    listen 80;

    server_name 10.0531.tw;

    access_log /data/wwwlogs/10.0531.tw_nginx.log combined;

    index index.html index.htm index.php;

    root /data/wwwroot/10.0531.tw;

    include /usr/local/nginx/conf/rewrite/none.conf;

    #error_page 404 /404.html;

    #error_page 502 /502.html;

    location / {

    proxy_pass http://127.0.0.1:5000;
    
    proxy_buffering off;
    
    proxy_cache off;
    
    proxy_set_header X-Forwarded-Proto $scheme;
    
    proxy_set_header X-Forwarded-For $remote_addr;
    
    proxy_set_header Host $proxy_host;
    

    }

    location ~ [^/].php(/|$) {

    #fastcgi_pass remote_php_ip:9000;
    
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    
    fastcgi_index index.php;
    
    include fastcgi.conf;
    

    }

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {

    expires 30d;
    
    access_log off;
    

    }

    location ~ .*.(js|css)?$ {

    expires 7d;
    
    access_log off;
    

    }

    location ~ /.ht {

    deny all;
    

    }

    }

    13 条回复    2019-05-13 09:14:54 +08:00
    Liang
        1
    Liang  
       2019-05-12 20:31:14 +08:00 via iPhone
    你是不是 80 被封了?
    jtnetcc
        2
    jtnetcc  
    OP
       2019-05-12 20:34:38 +08:00
    F12 查看了下,反代没起作用,走的 80 端口

    Request URL: http://10.0531.tw/

    Request Method: GET

    Status Code: 200 OK

    Remote Address: 35.201.165.176:80

    Referrer Policy: no-referrer-when-downgrade

    @Liang
    jtnetcc
        3
    jtnetcc  
    OP
       2019-05-12 20:37:06 +08:00
    @Liang 还有个默认的 nginx.conf 文件,是不是需要修改点什么?
    tangrwx
        4
    tangrwx  
       2019-05-12 20:58:50 +08:00 via iPhone
    手机上看的,如有失误,望包涵。

    看上去 js、css 没有成功加载,把 location js css 部分也指向 5000 端口,或者 root 指定的目录放上正确的 js、css
    just1
        5
    just1  
       2019-05-12 21:07:05 +08:00 via Android
    reload 了没
    liuzuo
        6
    liuzuo  
       2019-05-12 21:12:38 +08:00
    proxy_host 这个确定不是 host ?
    jtnetcc
        7
    jtnetcc  
    OP
       2019-05-12 21:17:05 +08:00
    @just1 重启过了 这个排除
    jtnetcc
        8
    jtnetcc  
    OP
       2019-05-12 21:17:48 +08:00
    @liuzuo 应该怎么写?
    jtnetcc
        9
    jtnetcc  
    OP
       2019-05-12 21:18:18 +08:00
    @tangrwx 对的 就是 css js 没加载成功。
    xiri
        10
    xiri  
       2019-05-12 21:30:26 +08:00 via Android
    你这个 nginx 配置只是用作反代的话需要把下面 php,css 之类的 location 全部删掉才行的。
    在 location 中,~和正则的优先级都比精准匹配的 /要高,也就是说当访问 domain/*.css 的时候会优先匹配 css 的那个 location 而忽略 location / {}的。
    更具体的楼主可以去查一下 nginx 配置中 location 的匹配优先级
    jtnetcc
        11
    jtnetcc  
    OP
       2019-05-12 21:35:56 +08:00
    @xiri 好了 谢谢 我屏蔽了正常了,精准匹配不会弄啊。
    Imr
        12
    Imr  
       2019-05-13 08:30:58 +08:00 via iPhone
    proxy_host 改 host
    wizardoz
        13
    wizardoz  
       2019-05-13 09:14:54 +08:00
    rewrite /(.*) /$1 break;
    proxy_pass http://127.0.0.1:5000;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3381 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.