A
A
alaskafx2022-04-07 19:28:29
Nginx
alaskafx, 2022-04-07 19:28:29

Why is .ru not added when redirecting?

I have this configuration:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
server_tokens off;
include /etc/nginx/mime.types;
default_type text/javascript;
access_log off;
error_log /var/log/nginx/error.log;
gzip on;
gzip_min_length 100;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
client_max_body_size 8M;
server {
    listen                  443 ssl http2;
    listen                  [::]:443 ssl http2;
    server_name             somesite.ru;

    # SSL
   ssl_certificate /etc/ssl/somesite.crt;
   ssl_certificate_key /etc/ssl/somesite.key;

    # reverse proxy
    location / {
        proxy_pass http://127.0.0.1:3000;
    }

}

# subdomains redirect
server {
    listen                  443 ssl http2;
    listen                  [::]:443 ssl http2;
    server_name             *.somesite.ru;

    # SSL
    ssl_certificate /etc/ssl/somesite.crt;
    ssl_certificate_key /etc/ssl/somesite.key;
    return                  301 https://somesite.ru$request_uri;
}

# HTTP redirect
server {
    listen      80;
    listen      [::]:80;
    server_name .somesite.ru;
    ssl_certificate /etc/ssl/somesite.crt;
    ssl_certificate_key /etc/ssl/somesite.key;

    location / {
        return 301 https://somesite.ru$request_uri;
    }
}
}

I'm trying to redirect from http to https, but when I try to go to http, I get an error saying that you need to check the host name, but it's not corny added to the address bar .ru, that is, it just looks like:https://somesite

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rst0, 2022-04-07
@Rst0

# HTTP redirect
server {
  charset utf-8;
  client_max_body_size 128M;
  listen 80;
        server_name *.somesite.ru;
         return 301 https://somesite.ru$request_uri;
}
# HTTPS 443
server {
    listen 443 ssl http2;
         server_name somesite.ru *.somesite.ru;
         ssl_certificate /etc/ssl/somesite.crt;
         ssl_certificate_key /etc/ssl/somesite.key;
    # reverse proxy
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header remote_addr $remote_addr;
  proxy_set_header   X-Forwarded-Proto $scheme;
  proxy_set_header   X-Forwarded-Port $server_port;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question