nginx中server配置的共同部分抽取
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 17:16:37
0
1
519

如下所示:

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块中是不可以的),谢谢!

过去多啦不再A梦
过去多啦不再A梦

全部回复(1)
阿神

已找到答案:

  1. 将location部分抽取到一个外部文件,如命名为:common_rules.conf,放到nginx目录下。

  2. 修改server配置为:

server {
    server_name  dev.drpb.com;
    root /Users/Stone/repo/oschina/drsoft/page-builder;
    include common_rules.conf;
}
server {
    server_name  dev.drp.com;
    root /Users/Stone/repo/oschina/drsoft/site;
    include common_rules.conf;
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板