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

2019-05-12 20:27:14 +08:00
 jtnetcc

环境是用 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;

}

}

3803 次点击
所在节点    NGINX
13 条回复
Liang
2019-05-12 20:31:14 +08:00
你是不是 80 被封了?
jtnetcc
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
2019-05-12 20:37:06 +08:00
@Liang 还有个默认的 nginx.conf 文件,是不是需要修改点什么?
tangrwx
2019-05-12 20:58:50 +08:00
手机上看的,如有失误,望包涵。

看上去 js、css 没有成功加载,把 location js css 部分也指向 5000 端口,或者 root 指定的目录放上正确的 js、css
just1
2019-05-12 21:07:05 +08:00
reload 了没
liuzuo
2019-05-12 21:12:38 +08:00
proxy_host 这个确定不是 host ?
jtnetcc
2019-05-12 21:17:05 +08:00
@just1 重启过了 这个排除
jtnetcc
2019-05-12 21:17:48 +08:00
@liuzuo 应该怎么写?
jtnetcc
2019-05-12 21:18:18 +08:00
@tangrwx 对的 就是 css js 没加载成功。
xiri
2019-05-12 21:30:26 +08:00
你这个 nginx 配置只是用作反代的话需要把下面 php,css 之类的 location 全部删掉才行的。
在 location 中,~和正则的优先级都比精准匹配的 /要高,也就是说当访问 domain/*.css 的时候会优先匹配 css 的那个 location 而忽略 location / {}的。
更具体的楼主可以去查一下 nginx 配置中 location 的匹配优先级
jtnetcc
2019-05-12 21:35:56 +08:00
@xiri 好了 谢谢 我屏蔽了正常了,精准匹配不会弄啊。
Imr
2019-05-13 08:30:58 +08:00
proxy_host 改 host
wizardoz
2019-05-13 09:14:54 +08:00
rewrite /(.*) /$1 break;
proxy_pass http://127.0.0.1:5000;

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/563420

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX