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;
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
|
show 1 more comment
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
Have a look at this stackoverflow.com/questions/15414810/….$host
variable will contain the first server that is defined in yourserver
block which is the value thatserver_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. Theserver_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
|
show 1 more comment
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
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
nginx ssl virtualhost configuration reverse-proxy
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 yourserver
block which is the value thatserver_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. Theserver_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
|
show 1 more comment
Have a look at this stackoverflow.com/questions/15414810/….$host
variable will contain the first server that is defined in yourserver
block which is the value thatserver_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. Theserver_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
|
show 1 more comment
1 Answer
1
active
oldest
votes
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
add a comment |
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;
add a comment |
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;
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;
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
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Have a look at this stackoverflow.com/questions/15414810/….
$host
variable will contain the first server that is defined in yourserver
block which is the value thatserver_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