Http换https转换 配置ssl证书

user root;

worker_processes 2;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

#log_format main 'remote_addr - remote_user $time_local "$request" '

'status body_bytes_sent "$http_referer" '

'"http_user_agent" "http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

#解决respose返回头过大导致nginx502报错

proxy_buffer_size 128k;

proxy_buffers 32 32k;

proxy_busy_buffers_size 128k;

server {

listen 80;

server_name youge.cn www.youge.cn;

return 301 https://hostrequest_uri;

}

server {

listen 443 ssl http2; # 启用 HTTPS 和 HTTP/2

#server_name youge.cn www.youge.cn;

SSL 证书配置

ssl_certificate /etc/nginx/youge.cn.crt; # 替换为实际路径

ssl_certificate_key /etc/nginx/youge.cn.key; # 替换为实际路径

添加中间证书

ssl_client_certificate /etc/nginx/youge.cn.pem;

ssl_trusted_certificate /etc/nginx/youge.cn.pem;

SSL 设置

ssl_protocols TLSv1.2 TLSv1.3; # 支持的协议版本

ssl_ciphers HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers on;

ssl_session_cache shared:SSL:1m;

ssl_session_timeout 10m;

ssl_stapling on;

ssl_stapling_verify on;

静态文件缓存

location / {

proxy_set_header Host $host;

set Real proxy_add_x_forwarded_for;

if ( $Real ~ (\d+)\.(\d+)\.(\d+)\.(\d+),(.*) ){

set Real 1.2.3.$4;

}

proxy_set_header X-real-ip $Real;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

#root /usr/share/nginx/html;

root /mnt/gdapros;

index index.html index.htm;

}

location /gateway2/ {

proxy_pass http://gatewayip:端口/;

proxy_set_header Host host:server_port;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $remote_addr;

#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

}

proxy_intercept_errors on;#打开错误拦截

}

}

相关推荐
梦到啥说啥14 小时前
Linux网络编程:TCP网络协议
网络·网络协议·tcp/ip
Jeremy_WW18 小时前
802.3协议解读 06:117章节 RS 和 200GMII / 400GMII I
网络·网络协议·信息与通信·光模块·802.3协议
杨凯凡18 小时前
Spring Framework 7 HTTP Interface 实战:声明式 RestClient、超时与测试
java·spring·http
沫璃染墨19 小时前
从零入门计算机网络系列(十八):TCP连接管理详解——从三次握手与四次挥手到TIME_WAIT机制
运维·服务器·网络·c++·网络协议·tcp/ip·tcp
CodeYp201920 小时前
第11讲:应用层协议 HTTP
linux·http
wdeok2 天前
Socket编程UDP-简单的聊天室
网络·网络协议·udp
Thanks_ks2 天前
HTTP 请求方法与 RESTful 接口设计:GET 和 POST 到底怎么用
http·api·restful·状态码·get·post·接口设计
LK_073 天前
【FastAPI】基础篇 01|开始之前:API、HTTP 与 FastAPI 到底是什么
网络协议·http·fastapi
阿星_3 天前
pydio登陆不了分析问题
网络协议·http·https
Joy T3 天前
Gzip 压缩原理与实践:HTTP 响应压缩、性能收益与工程配置
网络·网络协议·http