重定向
说的很好的一片文章
https://blog.csdn.net/chszs/article/details/26369257
ws相关配置
# 这个一定要配置
upstream 域名.com {
server ip:port;
}
server {
listen 80 ;
server_name 域名.com;
location / {
# 这个一定要配置与upsteam相当的的域名就行
proxy_pass http://域名.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
access_log /data0/logs/域名.com.log nginx_log;
}
wss相关配置
# 这个一定要配置
# ----重点输出-----
upstream wsbackend {
server ip:port; # 一定要写想要重定向的ip地址和端口,不要写域名
}
# ----重点输出-----
# 占用一个端口使其变为本地
# ----重点输出-----
server
{
listen 9510;
server_name 我的域名;
location / {
proxy_pass http://wsbackend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
# ----重点输出-----
server {
listen 443 http2 ssl;
# 这个一定要配置与upsteam相当的的域名就行
server_name 我的域名;
ssl on;
ssl_certificate /etc/conf/sinashow.com.cer;
ssl_certificate_key /etc/conf/sinashow.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_prefer_server_ciphers on;
# ----重点输出-----
location /wss/ {
proxy_pass http://127.0.0.1:9510; #通过配置端口指向部署websocker的项目
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
# ----重点输出-----
}
全局
# 流重定向
upstream wsbackend {
server 129.28.**.**:9501;
}
server
{
listen 9501;
server_name jeason.xyz;
location / {
proxy_pass http://wsbackend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
server
{
listen 80;
listen 443 ssl http2;
server_name jeason.xyz;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/jeason.xyz/public;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
#HTTP_TO_HTTPS_START
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
ssl_certificate /www/server/panel/vhost/cert/jeason.xyz/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/jeason.xyz/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-73.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/jeason.xyz.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log /dev/null;
}
access_log /www/wwwlogs/jeason.xyz.log;
error_log /www/wwwlogs/jeason.xyz.error.log;
}
虚拟
location /wss/ {
proxy_pass http://jeason.xyz:9501/; #通过配置端口指向部署websocker的项目
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}