nginx与https不同的端口

gcmastyq  于 2023-11-17  发布在  Nginx
关注(0)|答案(1)|浏览(254)

我遇到了一个问题,默认的HTTPS端口443已被使用。我将其切换到端口444,但现在我的网站只能通过'example.com:444'访问,当我尝试通过'https://example.com'访问我的网站时,它不起作用。如何在不显式指定端口的情况下配置它以使其工作?
这是我的nginx.conf

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. server {
  23. listen 80;
  24. server_name example.com www.example.com;
  25. #charset koi8-r;
  26. #access_log logs/host.access.log main;
  27. location / {
  28. proxy_pass http://localhost:8080;
  29. proxy_set_header X-Forwarded-Host $host;
  30. proxy_set_header X-Real-IP $remote_addr;
  31. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  32. proxy_set_header X-Forwarded-Proto $scheme;
  33. proxy_set_header Host $http_host;
  34. }
  35. #error_page 404 /404.html;
  36. # redirect server error pages to the static page /50x.html
  37. #
  38. error_page 500 502 503 504 /50x.html;
  39. location = /50x.html {
  40. root html;
  41. }
  42. }
  43. # HTTPS server
  44. #
  45. server {
  46. #listen 444 ssl http2 default_server;
  47. #listen [::]:444 ssl http2 default_server;
  48. listen 444 ssl;
  49. server_name example.com www.example.com;
  50. # Disable root application access. You may want to allow this in development.
  51. #location ~ ^/$ {
  52. # return 404;
  53. #}
  54. ssl_certificate C:\Users\Administrator\Desktop\ssl\wildcard24.pem;
  55. ssl_certificate_key C:\Users\Administrator\Desktop\ssl\wildcard24.pem;
  56. ssl_password_file C:\Users\Administrator\Desktop\ssl\psw.txt;
  57. ssl_session_cache shared:SSL:1m;
  58. ssl_session_timeout 5m;
  59. ssl_ciphers HIGH:!aNULL:!MD5;
  60. ssl_prefer_server_ciphers on;
  61. location / {
  62. proxy_pass http://localhost:8080;
  63. proxy_set_header X-Forwarded-Host $host;
  64. proxy_set_header X-Real-IP $remote_addr;
  65. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  66. proxy_set_header X-Forwarded-Proto $scheme;
  67. proxy_set_header Host $http_host;
  68. }
  69. }
  70. }

字符串
i希望在没有显式指定端口的情况下工作?
是否可以将我的服务器配置为侦听端口443,并确保所有请求(包括根URL(https://example.com)和子路径(例如https://example.com/map))都被重定向到同一端口上的所需页面,从而无需在URL中指定端口号?

cgyqldqp

cgyqldqp1#

HTTPS URL假定默认端口为443。(历史上HTTP URL假定为80)。
如果某个东西在端口444上运行,如果没有明确说明该端口号的URL,您就无法访问它。
如果这更多的是为了书签和方便(而不是隐藏端口号的外观必须是显式的),管理员通常会配置443服务器重定向到444服务器(https://example.com/other_server-> https://example.com:443/
还有其他更严肃的解决方案,更像是“服务器故障”(管理/配置)堆栈交换。

相关问题