linux - Problems with redirection of http and https first-level domain names and second-level domain names in Nginx
PHPz
PHPz 2017-05-16 13:19:44
0
3
966

~~I have a question for you seniors:
Today I enabled SSL support for the site. I want to do this:
No matter whether you visit https://domain.com or http://domain.com or http://www.domain.com, 301 automatically jumps to https://www.domain.com, that is to say, https://www.domain.com is the only access Url
. How should I write it? Configuration? This is how I do it:

But access will go wrong. Shows connection failure.
Remove

server {
    listen 443;
    server_name domain.com;
    return 301...
}

This section can be accessed normally, but accessing https://domain.com will not jump to https://www.domain.com

Is there any solution?
~~
Resolved: https://www.iots.vip/post/ngi...

PHPz
PHPz

学习是最好的投资!

reply all(3)
淡淡烟草味

The connection failed. What is the http status code? I feel like there is nothing wrong with this configuration.

server {
        listen 443 ssl;
        server_name www.test.com;
        root html;
        index index.html index.htm;
        ssl_verify_client off;
        ssl_certificate /etc/nginx/test.com.crt;
        ssl_certificate_key /etc/nginx/test.com.pem;
        ssl_client_certificate /etc/nginx/ca.com.crt;
        location / {
                proxy_set_header X-http-type https;
                proxy_set_header X-request-ip $remote_addr;
                proxy_pass http://127.0.0.1:9004/;
        }
        ssl_session_timeout 5m;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
        ssl_prefer_server_ciphers on;
    }
server {
        listen 443;
        server_name test.com;
        return 301 https://www.test.com$request_uri;

    }
server {
        listen 80;
        server_name test.com www.test.com;
        return 301 https://www.test.com$request_uri;

    }
    

It’s no problem for me, this way, I can jump.

仅有的幸福

The connection has been reset. There is no status code.

Peter_Zhu

Regarding the problem of domain.com jumping to www.domain.com, you can set it directly during domain name resolution

www A record 10.10.10.10
@ cname www.baidu.com. (remember there is a "dot" here)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!