標籤:詳解
#server定義一個虛擬機器主機
server
{
listen 80;
#網站的網域名稱,可以有多個
server_namewww.123.com www.abc.com;
#301網域名稱重新導向
if ($host != ‘www.123.com‘)
{
rewrite ^/(.*)$ http://www.123.com/$1 permanent;
}
index index.htmlindex.htm index.php;
#網站根目錄
root /data/www;
#訪問日誌存放路徑,aming為日誌的格式,自己定義,在nginx設定檔
access_log/tmp/access.log aming;
#存取控制,對於外部控制,越精確越優先匹配
#deny 127.0.0.1;
#插入一個檔案
#include deny.sh;
#使用者認證管理後台
location ~.*admin\.php$ {
#存取控制
#allow 127.0.0.1;
#deny all;
#使用者認證是通過apache的htpasswd工具
#auth_basic "tingshi";
#auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
#nginx和php-fpm通訊的方式,解析php指令碼
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
#解析php的根目錄
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|rar|zip|bz2)$
{
#gif|jpg|png等靜態檔案到期時間
expires 30d;
#不記錄gif|jpg|png等格式訪問日誌
access_log off;
#圖片,音樂等防盜鏈
valid_referers none blocked*.123.com *.abc.com;
if ($invalid_referer)
{
return 403;
}
}
location ~ .*\.(js|css)
{
#js|css靜態檔案到期時間
expires 12h;
#不記錄js|css等格式訪問日誌
access_log off;
}
location ~\.php$ {
#nginx和php-fpm通訊的方式,解析php指令碼
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#解析php的根目錄
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
#禁止指定的user_agent(搜尋引擎)
#if ($http_user_agent ~*‘curl|baidu|youdao‘)
# {
# return 403;
# }
}
#簡單虛擬機器主機
server
{
listen 80;
server_name www.woo.com;
index index.html index.htm index.php;
root /data/wordpress;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wordpress$fastcgi_script_name;
}
}
#nginx擴充
Nginx禁止某個目錄解析php
location ~ .*abc/.*\.php?$
{
deny all;
}
Nginx禁止訪問.txt檔案
location ~* \.(txt|doc)$ {
if (-f $request_filename) {
root/home/domain/public_html/test;
break;
}
}-
本文出自 “11736718” 部落格,請務必保留此出處http://11746718.blog.51cto.com/11736718/1876252
apache+nginx虛擬機器主機總設定檔