注意index,try_files指令的用法
server { listen 8803 default_server;
server_name test.php.360.cn;
root /data/www/test;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php; #try_files 會自動去掉末尾的斜杠
}
location ~ \.php$ {
try_files $uri =404; #最佳化檔案不存在的話提前報錯, fascgi 404 File not found.
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
server {
listen 80;
server_name yaf.com;
root /home/acmer1183/yaf/public;
index index.php index.html;
access_log /data/nginx/logs/yaf.com.access.log;
error_log /data/nginx/logs/yaf.com.error.log;
rewrite ^/$ /static/index.html last; #處理首頁跳轉
rewrite /\. /deny last; #禁止訪問隱藏檔案
location = /deny {
deny all;
}
location ^~ /static/ {
alias /home/acmer1183/yaf/static/;
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
location / {
try_files $uri $uri/ index.php;
}
}