Extract common parts of server configuration in nginx
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 17:16:37
0
1
445

As follows:

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;
    }
}

There are two server configuration blocks in the nginx configuration, and they have a common php reverse proxy configuration part.

How to add:

location ~ \.php$ {
    fastcgi_index  index.php;
    fastcgi_pass  127.0.0.1:9000;
    include fastcgi.conf;
}

Extract it and put it in one place instead of writing it once in each server (I tried putting it in the http block of its common parent but it didn't work), thank you!

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

reply all(1)
阿神

Answer found:

  1. Extract the location part to an external file, for example, name it: common_rules.conf, and put it in the nginx directory.

  2. Modify the server configuration to:

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;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!