nginx 如何禁止 ip 直接访问

2015-11-28 11:52:15 +08:00
 honmaple
原谅我网上教程没看懂
server {
listen 80 default_server;
server_name _;
return 444;
}
server {
listen 80 ;
server_name xxx.xxx;

# Handle all locations
location / {
# Pass the request to Gunicorn
proxy_pass http://127.0.0.1:8000;
proxy_redirect off;

# Set some HTTP headers so that our app knows where the
# request really came from
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 加上 default_server 后报错
nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/nginx.conf:47
nginx: configuration file /etc/nginx/nginx.conf test failed
如果不加那么没效果
去掉第一个 server 直接访问 ip 会出现 Welcome to nginx 页面

求助,环境是 python+flask+gunicorn+nginx
8307 次点击
所在节点    NGINX
25 条回复
honmaple
2015-11-29 16:00:03 +08:00
@Daddy 这个域名不错
honmaple
2015-11-29 16:01:11 +08:00
@salmon5 @ab 多谢,已经弄好了
honmaple
2015-11-29 16:02:49 +08:00
@pathbox 直接访问 ip 会出现 Welcome to nginx 页面这个页面,就想把它禁用了
icedream728
2015-11-30 10:34:22 +08:00
server {
server_name "";
return 500;
}
crystone
2015-11-30 13:06:47 +08:00
标记 学习了

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

https://tanronggui.xyz/t/239589

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

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

© 2021 V2EX