Welcome! Log In Create A New Profile

Advanced

Wildcard certificate - force redirect http to https for specific domain

Posted by rocklee44 
Wildcard certificate - force redirect http to https for specific domain
April 23, 2018 12:13PM
Hi all,
My environment : Centos 6.9 + rh-nginx18-nginx-1.8.1-1.el6.x86_64 .
I have wildcard certificate for domain *.mydomain.com , server accepts both http and https requests
[code]
server {
listen 192.168.0.19:80; # we serve both http and https
listen 192.168.0.19:443 default_server ssl;
server_name *.mydomain.com;
ssl_certificate
ssl_certificate_key
...
proxy_pass http://upstreams; we pass request to upstream based on some url conditions
}
[/code]
Now if I want to force redirect http to https for only 1 specific domain abc.mydomain.com and leave the rest remains the same, what should I do ?
I tried :
[code]
server {
listen 192.168.0.19:80;
server_name abc.mydomain.com;
return 301 https://$host$request_uri;
}

server {
listen 192.168.0.19:80; # we serve both http and https
listen 192.168.0.19:443 default_server ssl;
server_name *.mydomain.com;
ssl_certificate
ssl_certificate_key
...
proxy_pass http://upstreams; we pass request to upstream based on some url conditions
}
[/code]
But it doesn't work.
Please give me some advice, thank you very much.
Re: Wildcard certificate - force redirect http to https for specific domain
April 23, 2018 10:03PM
I tried remove "default_server" at listen entry , still not work, anyone get same problem ?
Re: Wildcard certificate - force redirect http to https for specific domain
April 25, 2018 10:01PM
This also doesn't work :
[code]
server {
listen 192.168.0.19:80; # we serve both http and https
listen 192.168.0.19:443 default_server ssl;
server_name *.mydomain.com;
ssl_certificate
ssl_certificate_key

if ($host = abc.mydomain.com) {set $test A;}
if ($scheme = http) {set $test "${test}B";}
if ($test = AB) {
return 301 https://$host$request_uri;
break;
}
...
}
[/code]
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 266
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready