如下所示:
server {
listen 80;
server_name dev.drpb.com;
root /Users/Stone/repo/oschina/drsoft/page-builder;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
}
server {
listen 80;
server_name dev.drp.com;
root /Users/Stone/repo/oschina/drsoft/site;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
}
在nginx配置中有兩個server配置區塊, 它們有共同的php反向代理配置部分.
請問如何將:
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
抽出來放到一個地方,而不是在每個server中都寫一次(我試著放到其共同父級的http區塊中是不可以的),謝謝!
已找到答案:
將location部分抽取到一個外部文件,如命名為:common_rules.conf,放到nginx目錄下。
修改server設定為: