Can I use variables in Nginx server block for SSL Cert and Key file?nginx with multiple servers and ssl cert, always use the same sslNeed NGINX Configured For Amazon EC2 / Wordpress - 502 bad gateway / 403 forbiddenCorrect configuration for SSL over 3 domains on same IP in nginxsetting up multiple ssl certificates on same server/ip on CENTOs with apache 2.2nginx domains using SSL cert listening but inaccessibleSSL connections reset with NginxNginX no longer redirecting non-www to www after Ubunutu restartIssue serving multiple SSL certs via nginxWhy Nginx calls for invalid certificate in non-existent subdomains just to redirect to 404?Nginx one SSL server interferes with all other http servers

What is the olden name for sideburns?

How well known and how commonly used was Huffman coding in 1979?

Why does this function call behave sensibly after calling it through a typecasted function pointer?

Quacks of Quedlingburg Crow Skull Set 2 Keep Drawing

Averting Real Women Don’t Wear Dresses

How to prove this countable intersection is empty?

Finding or mounting boot partition to create /boot/ssh

How should I behave to assure my friends that I am not after their money?

Why is Madam Hooch not a professor?

Can I use the PWM pins as regular digital input/output pins?

How can I create ribbons like these in Microsoft word 2010?

Are there any vegetarian astronauts?

Can a single server be associated with multiple domains?

What is the line crossing the Pacific Ocean that is shown on maps?

Alphabet completion rate

How can I convince my reader that I will not use a certain trope?

How could I adjust the text of a column in a table?

Is it allowed to spend a night in the first entry country before moving to the main destination?

How to determine what is the correct level of detail when modelling?

Can you sign using a digital signature itself?

Was touching your nose a greeting in second millenium Mesopotamia?

Analog is Obtuse!

I'm reinstalling my Linux desktop, how do I keep SSH logins working?

How do accents of a whole town drift?



Can I use variables in Nginx server block for SSL Cert and Key file?


nginx with multiple servers and ssl cert, always use the same sslNeed NGINX Configured For Amazon EC2 / Wordpress - 502 bad gateway / 403 forbiddenCorrect configuration for SSL over 3 domains on same IP in nginxsetting up multiple ssl certificates on same server/ip on CENTOs with apache 2.2nginx domains using SSL cert listening but inaccessibleSSL connections reset with NginxNginX no longer redirecting non-www to www after Ubunutu restartIssue serving multiple SSL certs via nginxWhy Nginx calls for invalid certificate in non-existent subdomains just to redirect to 404?Nginx one SSL server interferes with all other http servers






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm using Nginx Apache Reverse Proxy, I have multiple VHOSTS and I want to serve them all in a single nginx vhost file with support for SSL.



My server block is



 server 
listen 80;
server_name _;

root /var/www/$host/web;


access_log /var/log/mylogs/httpd/$host/access.log;

location /
try_files $uri $uri/ /index.php;


location ~ .php$
proxy_pass http://SERVERIP:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


location ~ /.
deny all;






This is working well without SSL for all sites BUT
when I do the same for SSL support below:



 server 
listen 80;
server_name _;

ssl on;
ssl_certificate /var/www/$host/ssl/$host-le.crt;
ssl_certificate_key /var/www/$host/ssl/$host-le.key;
root /var/www/$host/web;


access_log /var/log/mylogs/httpd/$host/access.log;

location /
try_files $uri $uri/ /index.php;


location ~ .php$
proxy_pass http://MYIP:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


location ~ /.
deny all;





I got errors something like this



ssl_certificate /var/www/$host/ssl/$host-le.crt not found
nginx config test failed


My vhost web files are in this format



/var/www/domain1.com/web
/var/www/domain2.com/web
/var/www/domain3.com/web



and their ssl cert and keys are in



/var/www/domain1.com/ssl
/var/www/domain2.com/ssl
/var/www/domain3.com/ssl



Please help me, I'm noob and still learning....










share|improve this question
























  • Have a look at this stackoverflow.com/questions/15414810/…. $host variable will contain the first server that is defined in your server block which is the value that server_name holds. This is not going to work for multiple domains the way you've configured nginx

    – Valentin Bajrami
    Oct 9 '17 at 9:20











  • Thanks for reply, Can I use $http_host instead?

    – Dark9Y8
    Oct 9 '17 at 9:25






  • 1





    No I don't think that works. The server_name doesn't resolve to the static name of your virtual web folder. Maybe this explains a bit better: drupal.org/node/1544144

    – Valentin Bajrami
    Oct 9 '17 at 9:36











  • Take a look at openresty-reference.readthedocs.io/en/latest/Directives/… This requires nginx patching or using OpenResty

    – Alexey Ten
    Oct 9 '17 at 16:02











  • Sounds like a hack. Where are the good old days when SSL certificates were read with root privileges which were dropped afterwards? Without knowing your business case and other requirements... what about one certificate for all domains? Certificates can be valid for multiple domains by listing them in their subject alternate name section. Let's encrypt supports up to 100 SAN entries.

    – blafasel
    Oct 9 '17 at 19:51


















1















I'm using Nginx Apache Reverse Proxy, I have multiple VHOSTS and I want to serve them all in a single nginx vhost file with support for SSL.



My server block is



 server 
listen 80;
server_name _;

root /var/www/$host/web;


access_log /var/log/mylogs/httpd/$host/access.log;

location /
try_files $uri $uri/ /index.php;


location ~ .php$
proxy_pass http://SERVERIP:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


location ~ /.
deny all;






This is working well without SSL for all sites BUT
when I do the same for SSL support below:



 server 
listen 80;
server_name _;

ssl on;
ssl_certificate /var/www/$host/ssl/$host-le.crt;
ssl_certificate_key /var/www/$host/ssl/$host-le.key;
root /var/www/$host/web;


access_log /var/log/mylogs/httpd/$host/access.log;

location /
try_files $uri $uri/ /index.php;


location ~ .php$
proxy_pass http://MYIP:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


location ~ /.
deny all;





I got errors something like this



ssl_certificate /var/www/$host/ssl/$host-le.crt not found
nginx config test failed


My vhost web files are in this format



/var/www/domain1.com/web
/var/www/domain2.com/web
/var/www/domain3.com/web



and their ssl cert and keys are in



/var/www/domain1.com/ssl
/var/www/domain2.com/ssl
/var/www/domain3.com/ssl



Please help me, I'm noob and still learning....










share|improve this question
























  • Have a look at this stackoverflow.com/questions/15414810/…. $host variable will contain the first server that is defined in your server block which is the value that server_name holds. This is not going to work for multiple domains the way you've configured nginx

    – Valentin Bajrami
    Oct 9 '17 at 9:20











  • Thanks for reply, Can I use $http_host instead?

    – Dark9Y8
    Oct 9 '17 at 9:25






  • 1





    No I don't think that works. The server_name doesn't resolve to the static name of your virtual web folder. Maybe this explains a bit better: drupal.org/node/1544144

    – Valentin Bajrami
    Oct 9 '17 at 9:36











  • Take a look at openresty-reference.readthedocs.io/en/latest/Directives/… This requires nginx patching or using OpenResty

    – Alexey Ten
    Oct 9 '17 at 16:02











  • Sounds like a hack. Where are the good old days when SSL certificates were read with root privileges which were dropped afterwards? Without knowing your business case and other requirements... what about one certificate for all domains? Certificates can be valid for multiple domains by listing them in their subject alternate name section. Let's encrypt supports up to 100 SAN entries.

    – blafasel
    Oct 9 '17 at 19:51














1












1








1








I'm using Nginx Apache Reverse Proxy, I have multiple VHOSTS and I want to serve them all in a single nginx vhost file with support for SSL.



My server block is



 server 
listen 80;
server_name _;

root /var/www/$host/web;


access_log /var/log/mylogs/httpd/$host/access.log;

location /
try_files $uri $uri/ /index.php;


location ~ .php$
proxy_pass http://SERVERIP:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


location ~ /.
deny all;






This is working well without SSL for all sites BUT
when I do the same for SSL support below:



 server 
listen 80;
server_name _;

ssl on;
ssl_certificate /var/www/$host/ssl/$host-le.crt;
ssl_certificate_key /var/www/$host/ssl/$host-le.key;
root /var/www/$host/web;


access_log /var/log/mylogs/httpd/$host/access.log;

location /
try_files $uri $uri/ /index.php;


location ~ .php$
proxy_pass http://MYIP:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


location ~ /.
deny all;





I got errors something like this



ssl_certificate /var/www/$host/ssl/$host-le.crt not found
nginx config test failed


My vhost web files are in this format



/var/www/domain1.com/web
/var/www/domain2.com/web
/var/www/domain3.com/web



and their ssl cert and keys are in



/var/www/domain1.com/ssl
/var/www/domain2.com/ssl
/var/www/domain3.com/ssl



Please help me, I'm noob and still learning....










share|improve this question
















I'm using Nginx Apache Reverse Proxy, I have multiple VHOSTS and I want to serve them all in a single nginx vhost file with support for SSL.



My server block is



 server 
listen 80;
server_name _;

root /var/www/$host/web;


access_log /var/log/mylogs/httpd/$host/access.log;

location /
try_files $uri $uri/ /index.php;


location ~ .php$
proxy_pass http://SERVERIP:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


location ~ /.
deny all;






This is working well without SSL for all sites BUT
when I do the same for SSL support below:



 server 
listen 80;
server_name _;

ssl on;
ssl_certificate /var/www/$host/ssl/$host-le.crt;
ssl_certificate_key /var/www/$host/ssl/$host-le.key;
root /var/www/$host/web;


access_log /var/log/mylogs/httpd/$host/access.log;

location /
try_files $uri $uri/ /index.php;


location ~ .php$
proxy_pass http://MYIP:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


location ~ /.
deny all;





I got errors something like this



ssl_certificate /var/www/$host/ssl/$host-le.crt not found
nginx config test failed


My vhost web files are in this format



/var/www/domain1.com/web
/var/www/domain2.com/web
/var/www/domain3.com/web



and their ssl cert and keys are in



/var/www/domain1.com/ssl
/var/www/domain2.com/ssl
/var/www/domain3.com/ssl



Please help me, I'm noob and still learning....







nginx ssl virtualhost configuration reverse-proxy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 9 '17 at 9:29







Dark9Y8

















asked Oct 9 '17 at 9:06









Dark9Y8Dark9Y8

163 bronze badges




163 bronze badges












  • Have a look at this stackoverflow.com/questions/15414810/…. $host variable will contain the first server that is defined in your server block which is the value that server_name holds. This is not going to work for multiple domains the way you've configured nginx

    – Valentin Bajrami
    Oct 9 '17 at 9:20











  • Thanks for reply, Can I use $http_host instead?

    – Dark9Y8
    Oct 9 '17 at 9:25






  • 1





    No I don't think that works. The server_name doesn't resolve to the static name of your virtual web folder. Maybe this explains a bit better: drupal.org/node/1544144

    – Valentin Bajrami
    Oct 9 '17 at 9:36











  • Take a look at openresty-reference.readthedocs.io/en/latest/Directives/… This requires nginx patching or using OpenResty

    – Alexey Ten
    Oct 9 '17 at 16:02











  • Sounds like a hack. Where are the good old days when SSL certificates were read with root privileges which were dropped afterwards? Without knowing your business case and other requirements... what about one certificate for all domains? Certificates can be valid for multiple domains by listing them in their subject alternate name section. Let's encrypt supports up to 100 SAN entries.

    – blafasel
    Oct 9 '17 at 19:51


















  • Have a look at this stackoverflow.com/questions/15414810/…. $host variable will contain the first server that is defined in your server block which is the value that server_name holds. This is not going to work for multiple domains the way you've configured nginx

    – Valentin Bajrami
    Oct 9 '17 at 9:20











  • Thanks for reply, Can I use $http_host instead?

    – Dark9Y8
    Oct 9 '17 at 9:25






  • 1





    No I don't think that works. The server_name doesn't resolve to the static name of your virtual web folder. Maybe this explains a bit better: drupal.org/node/1544144

    – Valentin Bajrami
    Oct 9 '17 at 9:36











  • Take a look at openresty-reference.readthedocs.io/en/latest/Directives/… This requires nginx patching or using OpenResty

    – Alexey Ten
    Oct 9 '17 at 16:02











  • Sounds like a hack. Where are the good old days when SSL certificates were read with root privileges which were dropped afterwards? Without knowing your business case and other requirements... what about one certificate for all domains? Certificates can be valid for multiple domains by listing them in their subject alternate name section. Let's encrypt supports up to 100 SAN entries.

    – blafasel
    Oct 9 '17 at 19:51

















Have a look at this stackoverflow.com/questions/15414810/…. $host variable will contain the first server that is defined in your server block which is the value that server_name holds. This is not going to work for multiple domains the way you've configured nginx

– Valentin Bajrami
Oct 9 '17 at 9:20





Have a look at this stackoverflow.com/questions/15414810/…. $host variable will contain the first server that is defined in your server block which is the value that server_name holds. This is not going to work for multiple domains the way you've configured nginx

– Valentin Bajrami
Oct 9 '17 at 9:20













Thanks for reply, Can I use $http_host instead?

– Dark9Y8
Oct 9 '17 at 9:25





Thanks for reply, Can I use $http_host instead?

– Dark9Y8
Oct 9 '17 at 9:25




1




1





No I don't think that works. The server_name doesn't resolve to the static name of your virtual web folder. Maybe this explains a bit better: drupal.org/node/1544144

– Valentin Bajrami
Oct 9 '17 at 9:36





No I don't think that works. The server_name doesn't resolve to the static name of your virtual web folder. Maybe this explains a bit better: drupal.org/node/1544144

– Valentin Bajrami
Oct 9 '17 at 9:36













Take a look at openresty-reference.readthedocs.io/en/latest/Directives/… This requires nginx patching or using OpenResty

– Alexey Ten
Oct 9 '17 at 16:02





Take a look at openresty-reference.readthedocs.io/en/latest/Directives/… This requires nginx patching or using OpenResty

– Alexey Ten
Oct 9 '17 at 16:02













Sounds like a hack. Where are the good old days when SSL certificates were read with root privileges which were dropped afterwards? Without knowing your business case and other requirements... what about one certificate for all domains? Certificates can be valid for multiple domains by listing them in their subject alternate name section. Let's encrypt supports up to 100 SAN entries.

– blafasel
Oct 9 '17 at 19:51






Sounds like a hack. Where are the good old days when SSL certificates were read with root privileges which were dropped afterwards? Without knowing your business case and other requirements... what about one certificate for all domains? Certificates can be valid for multiple domains by listing them in their subject alternate name section. Let's encrypt supports up to 100 SAN entries.

– blafasel
Oct 9 '17 at 19:51











1 Answer
1






active

oldest

votes


















0














Use $ssl_server_name variable instead of $host.

It can be used since Nginx 1.15.9 and OpenSSL 1.0.2 version.
http://nginx.org/ru/docs/http/ngx_http_ssl_module.html



ssl_certificate $ssl_server_name.crt;
ssl_certificate_key $ssl_server_name.key;





share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "2"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f877564%2fcan-i-use-variables-in-nginx-server-block-for-ssl-cert-and-key-file%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Use $ssl_server_name variable instead of $host.

    It can be used since Nginx 1.15.9 and OpenSSL 1.0.2 version.
    http://nginx.org/ru/docs/http/ngx_http_ssl_module.html



    ssl_certificate $ssl_server_name.crt;
    ssl_certificate_key $ssl_server_name.key;





    share|improve this answer





























      0














      Use $ssl_server_name variable instead of $host.

      It can be used since Nginx 1.15.9 and OpenSSL 1.0.2 version.
      http://nginx.org/ru/docs/http/ngx_http_ssl_module.html



      ssl_certificate $ssl_server_name.crt;
      ssl_certificate_key $ssl_server_name.key;





      share|improve this answer



























        0












        0








        0







        Use $ssl_server_name variable instead of $host.

        It can be used since Nginx 1.15.9 and OpenSSL 1.0.2 version.
        http://nginx.org/ru/docs/http/ngx_http_ssl_module.html



        ssl_certificate $ssl_server_name.crt;
        ssl_certificate_key $ssl_server_name.key;





        share|improve this answer















        Use $ssl_server_name variable instead of $host.

        It can be used since Nginx 1.15.9 and OpenSSL 1.0.2 version.
        http://nginx.org/ru/docs/http/ngx_http_ssl_module.html



        ssl_certificate $ssl_server_name.crt;
        ssl_certificate_key $ssl_server_name.key;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 10 at 10:05









        Thomas

        3,3484 gold badges15 silver badges25 bronze badges




        3,3484 gold badges15 silver badges25 bronze badges










        answered Jun 10 at 9:42









        user527115user527115

        1




        1



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Server Fault!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f877564%2fcan-i-use-variables-in-nginx-server-block-for-ssl-cert-and-key-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

            Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

            What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company