+135 410 16684Mon. - Fri. 10:00-22:00

CentOS 6 配置 Nginx 80自动跳转至443端口

CentOS 6 配置 Nginx 80自动跳转至443端口

CentOS 6 配置 Nginx 80自动跳转至443端口

1、yum 安装 nginx

配置 yum 源:
在 /etc/yum.repos.d/ 新建文件 nginx.repo ,写入如下内容:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

安装:

yum install nginx -y

2、配置 80 跳转 443(访问http协议时自动跳转到https协议)编辑 /etc/nginx/conf.d/default.conf 文件修改如下:

server {
listen 80;
server_name yunwei123.com;

rewrite ^(.*)$ https://$server_name$1 permanent;

access_log /var/log/nginx/host.http2https.access.log main;

}

3、https反向代理(https协议的访问实际是访问所代理的9800端口)

server {
listen 443;
server_name yunwei123.com;

ssl on;
ssl_certificate /etc/pki/tls/certs/lee.crt;
ssl_certificate_key /etc/pki/tls/certs/lee.key;

access_log /var/log/nginx/host.note.access.log main;

location / {

proxy_pass http://127.0.0.1:9800;

resolver_timeout 30s;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;

}

}