问题描述
Nginx将http和https请求重定向到端口3000。但是我试图将子域重定向到端口3001却没有成功,它正在被重定向到端口3000。没有登录错误。即使我尝试在端口80上执行http请求,也无法重定向端口3001,所有请求都转到3000。
然后我用子域配置了DNS。
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;
}
}
###################################################################
}
解决方法
一切都正确。我只需要删除浏览器缓存。