We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
假设我有一个域名为www.mysite.com,其绑定的主机IP地址为:120.24.23.22。现在我想禁止使用IP访问,当用IP访问的时候会跳转到带域名那种形式的访问。如何实现呢? 其实很简单的
创建过程可以参考我前面的文章,这里直接贴出代码:
server { listen 80; server_name www.mysite.com; access_log /home/wwwlogs/access_nginx.log combined; root /home/wwwroot/mysite; index index.html index.php; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } location ~ .*\.(php|php5)?$ { #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|ico)$ { expires 30d; access_log off; } location ~ .*\.(js|css)?$ { expires 7d; access_log off; } }
建议一个网站对应一个虚拟主机,虚拟主机最好不要建在nginx.conf配置文件里。
nginx.conf
接下来就是进行IP地址禁止访问的操作了,在nginx.conf文件中进行配置。配置信息如下:
server { listen 80 default_server; server_name _; rewrite ^ http://www.rulane.com$request_uri?; }
OK,重启服务器,如果配置没有错误的话,就没什么问题了。当我们通过120.24.23.22访问的时候,会自动跳转到www.mysite.com,这就是我们想要的结果
120.24.23.22
www.mysite.com
The text was updated successfully, but these errors were encountered:
感谢 @silenceper
下面的参考链接非常有帮助:
1.http://down.chinaz.com/server/201112/1469_1.htm
2.http://my.oschina.net/shootercn/blog/169761?fromerr=Oz1q75bK
3.http://blog.chinaunix.net/uid-25266990-id-3235543.html
Sorry, something went wrong.
🍻 🍻 🍻 🍻 🍻 🍻
@silenceper ❤️❤️❤️
No branches or pull requests
假设我有一个域名为www.mysite.com,其绑定的主机IP地址为:120.24.23.22。现在我想禁止使用IP访问,当用IP访问的时候会跳转到带域名那种形式的访问。如何实现呢? 其实很简单的
创建www.mysite.com的虚拟主机
创建过程可以参考我前面的文章,这里直接贴出代码:
建议一个网站对应一个虚拟主机,虚拟主机最好不要建在
nginx.conf
配置文件里。屏蔽IP地址访问的操作步骤
接下来就是进行IP地址禁止访问的操作了,在
nginx.conf
文件中进行配置。配置信息如下:OK,重启服务器,如果配置没有错误的话,就没什么问题了。当我们通过
120.24.23.22
访问的时候,会自动跳转到www.mysite.com
,这就是我们想要的结果The text was updated successfully, but these errors were encountered: