0
我的nginx的配置:Nginx如何縮短代碼?
location ~(\d*?)-(\d*?).news.html{
try_files $uri $uri/ /controller/news.php?id=$2&count=$3;
}
location ~/(\d*?)-(\d*?).journal.html {
try_files $uri $uri/ /controller/journal.php?id=$1&count=$2;
}
location ~/(\d*?)-(\d*?).event.html{
try_files $uri $uri/ /controller/event.php?id=$1&count=$2;
}
location ~ /news.php$ {
fastcgi_cache my_cache;
fastcgi_cache_key $scheme$host$request_uri$request_method;
#cache for 2 hours
fastcgi_cache_valid 200 2h;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /journal.php$ {
fastcgi_cache my_cache;
fastcgi_cache_key $scheme$host$request_uri$request_method;
#cache for 1 day
fastcgi_cache_valid 200 1d;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /event.php$ {
fastcgi_cache my_cache;
fastcgi_cache_key $scheme$host$request_uri$request_method;
#cache for 5 hours
fastcgi_cache_valid 200 5h;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
我有三個(或更多)locations
與重定向到相應的PHP腳本的HTML鏈接,並與不同的fastcgi_cache_valid
時間。
所以我需要添加六個location routes
來處理這樣的邏輯。但在底部,沒有緩存的php location route
是其他PHP腳本所必需的。
但是,所有php location route
都具有幾乎相同的屬性。如何共享php location route
?或者有沒有其他更簡單的方法來實現相同的機制?
感謝您的建議^ o ^ – user3711105