nginx - Nginx 子域重定向不起作用,所有请求都转到同一个端口
问题描述
Nginx 将 http 和 https 请求重定向到端口 3000。但我试图将子域重定向到端口 3001 没有成功,它被重定向到端口 3000。没有登录错误。即使我在端口 80 上尝试 http 请求,我也无法重定向端口 3001,所有请求都会转到 3000。
我用子域配置了 DNS。
我的 nginx.conf 文件是:
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name example.com www.example.com;
root /usr/share/nginx/html;
ssl_certificate "/etc/letsencrypt/live/example.com/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/example.com/privkey.pem";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:3000;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com.br www.example.com;
return 301 https://example.com;
}
############## THIS PART OF THE CODE IS IGNORED ###################
server {
listen 80;
listen [::]:80;
server_name subdomain.example.com;
location / {
proxy_pass http://127.0.0.1:3001;
}
}
###################################################################
}
原来这不是 nginx 的问题,我只需要删除浏览器缓存。
解决方案
一切都是正确的。我只需要删除浏览器缓存。
推荐阅读
- objective-c - ARC 不允许将“int”隐式转换为“UILabel *”
- html - 使用 select2 设置选择标签和背景的样式
- android - 哪个是在 android 中进行仪器测试的最佳框架?
- java - Activity启动时在线程中加载Recyclerview
- java - 使用 Apache POI 3.17 第二次读取和删除行后 Excel xlsx 文件损坏
- python - 使用 pygresql(pg 模块)在语句中执行 SQL 选择
- hyperledger-fabric - Hyperledger Fabric:组织是否可以以只读容量加入频道?
- javascript - 使用 javascript 反转链表
- postman - 如何使用邮递员生成和提供批量用户/数据
- canvas - 如何将 webgl 2d 比例原点从中心移动到左上角?