当前位置:   article > 正文

使用nginx将http重定向到https_nginx 重定向请求 直接返回

nginx 重定向请求 直接返回

nginx配置如下

  1. #user nobody; #配置用户可在文件上传的时候不报写入异常
  2. worker_processes 4;
  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. gzip on;
  23. gzip_comp_level 6;
  24. gzip_min_length 4k; # 小于4k的文件不会被压缩,大于4k的文件才会去压缩
  25. gzip_buffers 16 8k; # 处理请求压缩的缓冲区数量和大小,比如8k为单位申请16倍内存空间;使用默认即可,不用修改
  26. gzip_types text/plain application/x-javascript application/javascript text/javascript text/css application/xml application/x- httpd-php image/jpeg image/gif image/png application/vnd.ms-fontobject font/x-woff font/ttf;
  27. gzip_vary on; # 是否在http header中添加Vary: Accept-Encoding,一般情况下建议开启
  28. server {
  29. listen 80;
  30. server_name ip或域名;
  31. #charset koi8-r;
  32. #access_log logs/host.access.log main;
  33. rewrite ^(.*)$ https://$server_name$request_uri;
  34. #error_page 404 /404.html;
  35. # redirect server error pages to the static page /50x.html
  36. #
  37. error_page 500 502 503 504 /50x.html;
  38. location = /50x.html {
  39. root html;
  40. }
  41. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  42. #
  43. #location ~ \.php$ {
  44. # proxy_pass http://127.0.0.1;
  45. #}
  46. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  47. #
  48. #location ~ \.php$ {
  49. # root html;
  50. # fastcgi_pass 127.0.0.1:9000;
  51. # fastcgi_index index.php;
  52. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  53. # include fastcgi_params;
  54. #}
  55. # deny access to .htaccess files, if Apache's document root
  56. # concurs with nginx's one
  57. #
  58. #location ~ /\.ht {
  59. # deny all;
  60. #}
  61. }
  62. server {
  63. # 监听端口默认是8082
  64. listen 443 ssl;
  65. # 服务器ip或域名
  66. server_name ip或域名;
  67. # ssl证书(证书存放路径)
  68. ssl_certificate /usr/local/nginx/aaa.pem;
  69. ssl_certificate_key /usr/local/nginx/aaa.key;
  70. #if ($scheme = 'http') {
  71. # rewrite ^(.*)$ https://192.168.56.10:8082$request_uri;
  72. #}
  73. # 代理动态资源
  74. location ~ ^/yj {
  75. proxy_buffer_size 64k;
  76. proxy_buffers 32 32k;
  77. proxy_busy_buffers_size 128k;
  78. proxy_pass http://localhost:9208;
  79. proxy_set_header Host $host:80;
  80. proxy_max_temp_file_size 0k;
  81. proxy_connect_timeout 30;
  82. proxy_send_timeout 60;
  83. proxy_read_timeout 60;
  84. if ($request_uri ~ '/yj/admin') {
  85. proxy_pass http://localhost:9012;
  86. break;
  87. }
  88. if ($request_uri ~ '/yj/client') {
  89. proxy_pass http://localhost:9010;
  90. break;
  91. }
  92. }
  93. # 静态资源
  94. # location ~ \.(ico|js|css|png|jpg|mp4)$ {
  95. # proxy_pass http://192.168.140.130:8081;
  96. #}
  97. }
  98. # another virtual host using mix of IP-, name-, and port-based configuration
  99. #
  100. #server {
  101. # listen 8000;
  102. # listen somename:8080;
  103. # server_name somename alias another.alias;
  104. # location / {
  105. # root html;
  106. # index index.html index.htm;
  107. # }
  108. #}
  109. # HTTPS server
  110. #
  111. #server {
  112. # listen 443 ssl;
  113. # server_name localhost;
  114. # ssl_certificate cert.pem;
  115. # ssl_certificate_key cert.key;
  116. # ssl_session_cache shared:SSL:1m;
  117. # ssl_session_timeout 5m;
  118. # ssl_ciphers HIGH:!aNULL:!MD5;
  119. # ssl_prefer_server_ciphers on;
  120. # location / {
  121. # root html;
  122. # index index.html index.htm;
  123. # }
  124. #}
  125. }

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

闽ICP备14008679号