Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1328  / 2 Years ago, sun, august 21, 2022, 6:08:16

I have a SSL setup on my nginx server and the SSL works perfectly, only problem is it is working on all other virtual hosts and also the server IP which I don't want it to. It should only work in the same server block as the domain where the ssl is activated.



Here is the server blocks:



server {
listen 80;
root /var/www;
index index.html index.htm index.php;
server_name SERVER.IP.HERE;

location / {
try_files $uri $uri/ /index.html;
}

location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

server {
listen 443;
server_name SERVER.IP.HERE;

ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
}

server {
listen 80;
root /var/www/example.com;
index index.html index.htm index.php;
server_name example.com;

location / {
try_files $uri $uri/ /index.html;
}
}


I want the ssl to work on the server IP and NOT the example.com virtual host. What's the best way to do this?



Thanks.


More From » server

 Answers
4

I didn't try it, but I think a redirection should work.



Try adding this after the server block where you configure the SSL connection on the IP :



server {
listen 443;
server_name *;
return 301 http://$http_host$request_uri;
}

[#25285] Tuesday, August 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
otputler

Total Points: 53
Total Questions: 105
Total Answers: 93

Location: Zimbabwe
Member since Wed, Nov 9, 2022
2 Years ago
otputler questions
Tue, Aug 23, 22, 14:36, 2 Years ago
Fri, Jul 23, 21, 11:57, 3 Years ago
Sun, Feb 12, 23, 18:37, 1 Year ago
;