虚拟主机配置文件详解
server
{
listen 80;
server_name www.yanghao.com www.yangqiding.com www.yangteng.com; 配置域名及访问端口
if ($host != 'www.yanghao.com')
{ 配置域名301跳转
rewrite ^/(.*)$ http://www.yanghao.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
access_log /tmp/access.log yanghao; 定义日志类型
# deny 127.0.0.1;
if ($http_user_agent ~ 'curl|Firefox|Chrome')
{ 配置禁止user_agent
return 403;
}
location ~ .*admin\.php$ {
# auth_basic "yangqiding auth";
# auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
allow 192.168.238.1;
deny all; 配置用户认证
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|rar|zip|gz|bz2)$
{
access_log off;
expires 15d;
valid_referers none blocked *.yanghao.com *.yangqiding.com *.yangteng.com;
if ($invalid_referer)
{
return 403;
}
}
location ~ \.(js|css) 配置防盗链、制定不记录制定文件类型及静态文件过期时间
{
access_log off;
expires 2h;
}
location ~ (static|cache)
{
access_log off;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
# fastcgi_pass 127.0.0.1:9000; 常见的502问题解决
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
server
{
listen 80;
server_name www.yanghao.com www.yangqiding.com www.yangteng.com; 配置域名及访问端口
if ($host != 'www.yanghao.com')
{ 配置域名301跳转
rewrite ^/(.*)$ http://www.yanghao.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
access_log /tmp/access.log yanghao; 定义日志类型
# deny 127.0.0.1;
if ($http_user_agent ~ 'curl|Firefox|Chrome')
{ 配置禁止user_agent
return 403;
}
location ~ .*admin\.php$ {
# auth_basic "yangqiding auth";
# auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
allow 192.168.238.1;
deny all; 配置用户认证
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|rar|zip|gz|bz2)$
{
access_log off;
expires 15d;
valid_referers none blocked *.yanghao.com *.yangqiding.com *.yangteng.com;
if ($invalid_referer)
{
return 403;
}
}
location ~ \.(js|css) 配置防盗链、制定不记录制定文件类型及静态文件过期时间
{
access_log off;
expires 2h;
}
location ~ (static|cache)
{
access_log off;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
# fastcgi_pass 127.0.0.1:9000; 常见的502问题解决
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
编辑回复