W
W
winmasta2017-05-30 06:20:39
Nginx
winmasta, 2017-05-30 06:20:39

How to correctly configure forwarding from 80 to 443 port in nginx proxypass?

Good afternoon, there is such a setting NGINX
server {
listen 80;
listen 443 ssl;
# return 301 https://$server_name$request_uri;
server_name SERVER_NAME;
ssl_certificate /etc/letsencrypt/live/SERVER_NAME/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/keys/0008_key-certbot.pem;
ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
access_log /var/log/nginx/SERVER_NAME_proxy.log;
location / {
proxy_pass http://192.168.169.4;
}
}
If you log in via https, then everything is as it should be - a secure connection, if via 80, then no. I found an instruction on the net with return 301, but if this line is uncommented, it looks like it starts redirecting itself many times and the page does not open, what am I doing wrong? I am happy to read links on the topic.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Zubkov, 2017-05-30
@winmasta

Make two blocks, don't write 80 and 443 in one server

server {
listen 80;
server_name ИМЯ_СЕРВЕРА;
return 301 https://$server_name$request_uri;

}

server {
listen 443 ssl;
server_name ИМЯ_СЕРВЕРА;
ssl_certificate /etc/letsencrypt/live/ИМЯ_СЕРВЕРА/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/keys/0008_key-certbot.pem;
ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
access_log /var/log/nginx/ИМЯ_СЕРВЕРА_proxy.log;
location / {
proxy_pass http://192.168.169.4;
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question