8

I have to configure multi https website with a dedicated certificate for each website. It works fine like that.

server {
        listen   443;
        server_name client1.localhost.eu;

        ssl on;
        ssl_certificate ...;
        ssl_certificate_key ...;

        root   /var/www/client1;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm-client1.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
}

server {
        listen   443;
        server_name client2.localhost.eu;

        ssl on;
        ssl_certificate ...;
        ssl_certificate_key ...;

        root   /var/www/client2;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm-client2.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
}

Now, I would like to factorize the "location" block, because it is always the same. Is it possible ? (I have also tried to have only on server block, but it's not possible to put a variable in the ssl attribute)

Thanks a lot for your help.

Eric

1 Answer 1

12

Use include directive for such factorization:

include

Create file in the nginx config folder like /etc/nginx/conf.d/location_php.cnf (not .conf to avoid auto-loading by nginx)

location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm-client2.sock;
            fastcgi_index index.php;
            include fastcgi_params;
}

and then include it into server blocks:

server {
        listen   443;
        server_name client1.localhost.eu;

        ssl on;
        ssl_certificate ...;
        ssl_certificate_key ...;

        root   /var/www/client1;
        include /etc/nginx/conf.d/location_php.cnf;
        # OR use relative path to nginx config root:
        # include conf.d/location_php.cnf;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.