vim nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
#禁止通过ip来访问域名,当使用IP地址来访问网站时,默认会匹配第一个server条目,所以只要第一个server配置禁止访问,就可以防止通过ip来访问网站
listen 80;
location / {
deny all;
}
}
server {
listen 80;
server_name www.linuxmysql.com;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name linuxmysql.com;
rewrite ^/(.*) http://www.linuxmysql.com/$1 permanent;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name bbs.linuxmysql.com;
location / {
root html/bbs;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name blog.linuxmysql.com;
location / {
root html/blog;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name status.linuxmysql.com;
stub_status on;
access_log off;
}
}
测试:
在windows主机主配置hosts:
vim C:\WINDOWS\system32\drivers\etc\hosts
127.0.0.1 localhost
192.168.198.130 www.linuxmysql.com
192.168.198.130 blog.linuxmysql.com
192.168.198.130 bbs.linuxmysql.com
192.168.198.130 linuxmysql.com
192.168.198.130 status.linuxmysql.com
访问:
http://192.168.198.130
网页会出现:
403 Forbidden
--------------------------------------------------------------------------------
nginx/1.6.2
2017-08-08
禁止通过IP访问网站nginx.conf
评论
发表评论
姓 名: