我遇到的问题是默认 HTTPS 端口 443 已被使用。我将其切换到端口 444,但现在我的网站只能通过“https://example.com:444”访问,当我尝试通过“https://example.com”访问我的网站时,它不起作用。如何在不明确指定端口的情况下将其配置为工作?
这是我的 nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name example.com www.example.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# HTTPS server
#
server {
#listen 444 ssl http2 default_server;
#listen [::]:444 ssl http2 default_server;
listen 444 ssl;
server_name example.com www.example.com;
# Disable root application access. You may want to allow this in development.
#location ~ ^/$ {
# return 404;
#}
ssl_certificate C:\Users\Administrator\Desktop\ssl\wildcard24.pem;
ssl_certificate_key C:\Users\Administrator\Desktop\ssl\wildcard24.pem;
ssl_password_file C:\Users\Administrator\Desktop\ssl\psw.txt;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
}
}
}
我希望在不明确指定端口的情况下工作?
是否可以将我的服务器配置为侦听端口 443 并确保所有请求,包括根 URL (https://example.com) 和子路径(例如,https://example.com/map) ),重定向到同一端口上的所需页面,从而无需在 URL 中指定端口号?
HTTPS URL 假定默认端口为 443。(历史上 HTTP URL 假定为 80)。
如果某些内容正在端口 444 上运行,则如果没有明确指出该端口号的 URL,您将无法访问它。
如果这更关心书签和便利性(而不是隐藏端口号的外观,必须是明确的),管理员通常会配置 443 服务器以重定向到 444 服务器(https://example.com/其他_服务器 -> https://example.com:443/)
还有其他更严重的解决方案,这更像是“服务器故障”(管理/配置)堆栈交换。