nginx http redirection https configuration instructions

  • 2020-05-13 04:33:36
  • OfStack

nginx http redirection https configuration instructions

现在什么苹果,谷歌浏览器请求地扯基本都要求使用https了,如何把原来的http协议重定向到https中呢,这里我们可以使用http反向代理软件nginx。

use

The installation


yum install nginx -y

configuration


cat /etc/nginx

server {
 listen 80;
 server_name dounine.com www.dounine.com;
 return  301 https://www.dounine.com$request_uri;
}
server {
 listen 443;
 server_name dounine.com dounine.com;
 return  301 https://www.dounine.com$request_uri;
}
server {
 listen 443;
 server_name www.dounine.com;
 ssl on;
 ssl_certificate /etc/nginx/dounine.crt;
 ssl_certificate_key /etc/nginx/dounine.key;

 location / {
 client_max_body_size 20m;
 proxy_pass http://127.0.0.1:8080;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }
}

The above configuration can be www. dounine. com, dounine. com and https: / / dounine com redirected to https: / / www dounine. com to pull.

Pay attention to

Remember to open ports 80 and 443 of the firewall.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: