首先声明,非专业研究nginx的,可以直接复制我的代码到 nginx 配置中再根据个人需求更改
非80端口通过80端口反向代理到非80端口应用,添加下面代码到nginx配置文件最后
server_name:写你的域名
proxy_pass?域名:端口号(ip:端口号)?
安装?SSL?证书推荐强制 HTTPS
server{
listen 80;
listen 443 ssl http2;
server_name xxx.com;
index index.php index.html index.htm default.php default.htm default.html;
#强制 HTTPS,域名有证书才启用,没证书请注释掉
#HTTP_TO_HTTPS_START
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
#证书
ssl_certificate /www/server/panel/vhost/cert/fullchain.pem;#证书PEM
ssl_certificate_key /www/server/panel/vhost/cert/privkey.pem;#证书KEY
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
#error_page 497 301 https://$http_host$request_uri;
#error_page 497 https://$host$request_uri;
location / {
proxy_pass http://xxx.xxx.xxx.xxx:65535; #反向代理到65535端口
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header Upgrade-Insecure-Requests 1;
proxy_set_header X-Forwarded-Proto https;
}
}
可以去我的网站看看效果(领取京豆登录页为反向代理应用)技术无罪 (jswz.icu)https://jswz.icu/
|