访问 www.a.com 自动跳到 www.b.com(301跳转设置)
server {
listen 80;
server_name www.a.com;
rewrite ^/(.*)$ http://www.b.com/$1 permanent;
}
主目录跳转,子目录不跳转
server {
listen 80;
server_name www.a.us a.us;
#根目录跳转
location / {
rewrite .+ http://www.b.com/ permanent;
}
location ~* /.+ {
#已省略余下通用配置内容
}
}
302跳转
server {
listen 80;
server_name 123.com;
rewrite ^/(.*) http://456.com/$1 redirect;
access_log off;
}
禁止多个目录
location ~ ^/(cron|templates)/ {
deny all;
break;
}
禁止htaccess
location ~//.ht {
deny all;
}
禁止以/data开头的文件
可以禁止/data/下多级目录下.log.txt等请求;
location ~ ^/data {
deny all;
}
只充许固定ip访问网站,并加上密码
root /opt/htdocs/www;
allow 208.97.167.194;
allow 222.33.1.2;
allow 231.152.49.4;
deny all;
auth_basic "C1G_ADMIN";
auth_basic_user_file htpasswd;
多域名转向
server_name www.c1gstudio.com www.c1gstudio.net;
index index.html index.htm index.php;
root /opt/lampp/htdocs;
if ($host ~ "c1gstudio/.net") {
rewrite ^(.*) http://www.c1gstudio.com$1 permanent;
}
三级域名跳转
if ($http_host ~* "^(.*)/.i/.c1gstudio/.com$") {
rewrite ^(.*) http://top.yingjiesheng.com$1;
break;
}