当前位置:   article > 正文

Nginx将http重定向到https,一直提示重定向次数过多(已解决)_将您重定向的次数过多

将您重定向的次数过多

先贴一下nginx的配置

  1. http {
  2. include mime.types;
  3. default_type application/octet-stream;
  4. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  5. # '$status $body_bytes_sent "$http_referer" '
  6. # '"$http_user_agent" "$http_x_forwarded_for"';
  7. #access_log logs/access.log main;
  8. sendfile on;
  9. #tcp_nopush on;
  10. #keepalive_timeout 0;
  11. keepalive_timeout 65;
  12. #gzip on;
  13. server {
  14. listen 80;
  15. server_name e.com;
  16. # rewrite ^(.*) https://$server_name$1 permanent;
  17. return 301 https://$host$request_uri;
  18. # gzip config
  19. gzip on;
  20. gzip_min_length 1k;
  21. gzip_comp_level 9;
  22. gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
  23. gzip_vary on;
  24. gzip_disable "MSIE [1-6]\.";
  25. root /opt/hengze/dist;
  26. location / {
  27. root /dist;
  28. index index.html;
  29. }
  30. #error_page 404 /404.html;
  31. # redirect server error pages to the static page /50x.html
  32. #
  33. error_page 500 502 503 504 /50x.html;
  34. location = /50x.html {
  35. root html;
  36. }
  37. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  38. #
  39. #location ~ \.php$ {
  40. # proxy_pass http://127.0.0.1;
  41. #}
  42. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  43. #
  44. #location ~ \.php$ {
  45. # root html;
  46. # fastcgi_pass 127.0.0.1:9000;
  47. # fastcgi_index index.php;
  48. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  49. # include fastcgi_params;
  50. #}
  51. # deny access to .htaccess files, if Apache's document root
  52. # concurs with nginx's one
  53. #
  54. #location ~ /\.ht {
  55. # deny all;
  56. #}
  57. location ^~/api/ {
  58. proxy_pass https://e.com/; #修改此地址为后台服务地址
  59. proxy_set_header X-Forwarded-Proto $scheme;
  60. proxy_set_header Host $host:$server_port;
  61. proxy_set_header X-Real-IP $remote_addr;
  62. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  63. proxy_http_version 1.1;
  64. proxy_set_header Upgrade $http_upgrade;
  65. proxy_set_header Connection "upgrade";
  66. proxy_connect_timeout 1;
  67. proxy_buffering off;
  68. chunked_transfer_encoding off;
  69. proxy_cache off;
  70. proxy_send_timeout 30m;
  71. proxy_read_timeout 30m;
  72. client_max_body_size 100m;
  73. }
  74. }
  75. # another virtual host using mix of IP-, name-, and port-based configuration
  76. #
  77. #server {
  78. # listen 8000;
  79. # listen somename:8080;
  80. # server_name somename alias another.alias;
  81. # location / {
  82. # root html;
  83. # index index.html index.htm;
  84. # }
  85. #}
  86. # HTTPS server
  87. #
  88. server {
  89. listen 443 ssl;
  90. server_name e.com;
  91. ssl_certificate cert/e.com.pem;
  92. ssl_certificate_key cert/e.com.key;
  93. ssl_session_cache shared:SSL:1m;
  94. ssl_session_timeout 5m;
  95. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  96. ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
  97. ssl_prefer_server_ciphers on;
  98. location / {
  99. # 解决wesock问题
  100. proxy_http_version 1.1;
  101. proxy_set_header Upgrade $http_upgrade;
  102. proxy_set_header Connection "upgrade";
  103. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  104. proxy_set_header X-Real-IP $remote_addr;
  105. #从这里往下三行处理前后端服务在一个服务器中
  106. proxy_set_header X-Real-IP $remote_addr;
  107. proxy_set_header Host $http_host;
  108. proxy_pass http://localhost;
  109. }
  110. }
  111. }

return和rewrite都已经试过了,都是多次重定向导致无法进入页面

后续在https区域中将连接后端地址的api区域复制过来后,再加上下方代码完美解决

#将所有HTTP请求通过rewrite指令重定向到HTTPS。

rewrite ^(.*)$ https://$host$1;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/590995
推荐阅读
相关标签
  

闽ICP备14008679号