Score:0

Redirect nginx port 80 to http2 443 fails

cn flag

Searched tons of links on the web, I don't get why this conf doesn't redirect properly from http://example.com to https://example.com

My conf:

# HTTPS
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    index index.html;

    # Prevent nginx HTTP Server Detection
    server_tokens off;

    server_name example.org;
    root /home/www/example.org;

    # Let's Encrypt conf
    include /etc/nginx/ssl.conf;

    access_log  /var/log/nginx/example.org.access.log;
}

# HTTP redirect
server {
    listen 80;
    listen [::]:80;

    server_name example.org;

    location / {
        return 301 https://$server_name$request_uri;

    }
}

netstat:

# netstat -nptl | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      71768/nginx: master 
tcp6       0      0 :::80                   :::*                    LISTEN      71768/nginx: master 

What I'm doing wrong?

When I try curl, I get:

$ curl -Lv http://example.org
*   Trying 123:123:123:123:80...
* Connected to example.org (123:123:123:123) port 80 (#0)
> GET / HTTP/1.1
> Host: example.org
> User-Agent: curl/7.81.0
> Accept: */*
>
* Received HTTP/0.9 when not allowed
* Closing connection 0
curl: (1) Received HTTP/0.9 when not allowed

And a telnet:

$ telnet example.org 80
Trying 123:123:123:123...
Connected to example.org.
Escape character is '^]'.
GET / HTTP/1.1
Connection closed by foreign host.

Let'sEncrypt file

ssl_certificate /etc/letsencrypt/live/example.org-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.org-0001/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/private/dh2048.pem;
add_header Strict-Transport-Security "max-age=63072000";
ssl_session_cache shared:SSL:1m;

No issue with SSL vhost.

HBruijn avatar
in flag
Possibly you have one or more additional server blocks you haven't disclosed and that the problem could be in there. Please edit your question to include the output of `nginx -T` - an example of a similar issue where the problem was related to a 'spdy' or 'http2' directives in a different server entry on port 80 https://serverfault.com/q/1041653/37681
Score:3
us flag

Try replacing

server {
    listen 80;
    listen [::]:80;

    server_name example.org;

    location / {
        return 301 https://$server_name$request_uri;

    }
}

with

server {
    listen 80;
    listen [::]:80;

    server_name example.org;
    return 301 https://$server_name$request_uri;
}
Mévatlavé Kraspek avatar
cn flag
No, it doesn't work. Same error with `curl` and https://downforeveryoneorjustme.com/ said it's down on http
Mévatlavé Kraspek avatar
cn flag
The 80 port is reachable as client side
Rado avatar
us flag
my letsencrypt conf has 3 lines `ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem; include snippets/ssl-params.conf;` ... are you sure, you're including everything ?
Mévatlavé Kraspek avatar
cn flag
The 443 `vhost` works as a charm. The 80 one, have no `ssl` conf
Mévatlavé Kraspek avatar
cn flag
Added LetsEncrypt file in my original POST
Mévatlavé Kraspek avatar
cn flag
Issue find, see duplicated, plused+
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.