将nginx需要的ssl配置的秘钥文件复制到centos服务器上,放在nginx安装目录下ssl文件夹(自己创建),在nginx.conf文件中对进行配置
server {
listen 443 ssl;
server_name xxx.com:8080;
access_log /data/wwwlogs/access_nginx.log combined;
root xxxx;
index index.html index.htm index.jsp;
#error_page 404 /404.html;
#error_page 502 /502.html;
ssl_certificate /usr/local/nginx/ssl/xxx.crt;
ssl_certificate_key /usr/local/nginx/ssl/xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
proxy_pass http://localhost:8080;
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
proxy_pass http://localhost:8080;
access_log off;
}
location / {
proxy_pass http://127.0.0.1:8080; # 转发规则
proxy_set_header Host $proxy_host; # 修改转发请求头,让8080端口的应用可以受到真实的请求
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {
deny all;
}
}
server
{
# 80端口是http正常访问的接口
listen 80;
server_name xxx;#域名
# 在这里,我做了https全加密处理,在访问http的时候自动跳转到https
rewrite ^(.*) https://$host$1 permanent;
}
配置好即可通过https加密方式访问
评论区