当前位置:首页>开发>正文

怎么用nginx不同域名指向同一IP不同端口 nginx rewrite怎么获取当前域名

2023-04-20 04:35:06 互联网 未知 开发

 怎么用nginx不同域名指向同一IP不同端口 nginx rewrite怎么获取当前域名

怎么用nginx不同域名指向同一IP不同端口

:9000,设置server_name为ip 端口server {listen 9000.xxcharset utf-8server_name xx..xx..xx;....}重启设置你监听的端口

nginx rewrite怎么获取当前域名

当前域名可以使用 $host 代替
列如:
location /admin {
rewrite ^/(.*) http://$host/mh.admin/login.php permanent
}
上面的意思是 当域名后面接的是admin 是跳转到 域名/mh.admin/login.php

nginx 如何同时配置https和wss

nginx同时配置https和wss代码如下:
server {
listen 443 ssl
server_name localhost
ssl on
root html
index index.html index.htm
ssl_certificate   ******.pem
ssl_certificate_key  *******.key
ssl_session_timeout 5m
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4
ssl_protocols TLSv1 TLSv1.1 TLSv1.2
ssl_prefer_server_ciphers on
location /{
proxy_pass   https://localhost:3001
}

location /ws {
proxy_pass https://localhost:8181 
proxy_read_timeout 60s
proxy_http_version 1.1
proxy_set_header Upgrade $http_upgrade
proxy_set_header Connection Upgrade
}   

}
WebSocket协议的握手和HTTP是兼容的,它使用HTTP的Upgrade协议头将连接从HTTP连接升级到WebSocket连接。这个特性使得WebSocket应用程序可以很容易地应用到现有的基础设施。就可以使用https// 域名访问和使用wss:// 域名+/ws访问了

最新文章