Website does not forward to https (part2) [SOLVED]

Hello it’s me again ^^.

I have a slight problem that I believe I had before but it could be now something else.

The problem is the following:

  • if you open cp2077.eu on browser, then the page says its “under maintenance” which is a template of mine of course and it’s not secure.

  • but if you open https://cp2077.eu , then the discourse forum appears and the website looks secure with SSL.

My guess is that my nginx file is not taking account redirecting page to https. Here is my file, I have checked but I don’t know where the problem is, it looks fine (I think it looks fine) but maybe someone with more knowledge can help me sort this issue out? I would appreciate:

server {

    listen 80;
    listen [::]:80;
    server_name www.cp2077.eu;
    return 301 https://cp2077.eu$request_uri;
}

server {

    listen 443 ssl;
    listen [::]:443 ssl;
    server_name www.cp2077.eu;
    ssl_certificate /etc/letsencrypt/live/cp2077.eu/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cp2077.eu/privkey.pem;
    return 301 https://cp2077.eu$request_uri;
}

server {

    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name cp2077.eu;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/cp2077.eu/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cp2077.eu/privkey.pem;



    http2_idle_timeout 5m; # up from 3m default

    location / {
        proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Real-IP $remote_addr;

    }

}

Any clue what could I change here to resolve it?

You allow only ẁww..

How can I redirect www and cp2077.eu to be redirected to https?

Try adding the domain.

server_name cp2077.eu www.cp2077.eu;

Tried that before posting, it throws me the following error when running command: nginx -t

nginx: [warn] conflicting server name "cp2077.eu" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "cp2077.eu" on [::]:443, ignored

Did you add it only in the first server {} (port 80)?

3 Likes

I added it on both 80 and 443

—Edit.

I just put it on 80 and looks like its working. However now it says that Connection not secure (parts of this page are not secure, such as images)_

You should enable force https in discourse settings.

1 Like

I will try that. Thank you very much Arkshine

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.