Nginx.config 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ##
  2. # You should look at the following URL's in order to grasp a solid understanding
  3. # of Nginx configuration files in order to fully unleash the power of Nginx.
  4. # https://www.nginx.com/resources/wiki/start/
  5. # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
  6. # https://wiki.debian.org/Nginx/DirectoryStructure
  7. #
  8. # In most cases, administrators will remove this file from sites-enabled/ and
  9. # leave it as reference inside of sites-available where it will continue to be
  10. # updated by the nginx packaging team.
  11. #
  12. # This file will automatically load configuration files provided by other
  13. # applications, such as Drupal or Wordpress. These applications will be made
  14. # available underneath a path with that package name, such as /drupal8.
  15. #
  16. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  17. ##
  18. # Default server configuration
  19. #
  20. #####兼容客户端Firefox 27, Chrome 30, IE 11 on Windows 7, Edge, Opera 17, Safari 9, Android 5.0, and Java 8
  21. #####此文件的真身路径是 /etc/nginx/sites-available/default 如果你修改了 /etc/nginx/nginx.conf 中的内容,但
  22. #####/etc/nginx/sites-available/default 中的 参数 与 前者 重叠 那么 会 遵从 后者
  23. server {
  24. #listen 80 default_server;
  25. #listen [::]:80 default_server;
  26. # SSL configuration
  27. #
  28. # listen 443 ssl default_server;
  29. # listen [::]:443 ssl default_server;
  30. #
  31. # Note: You should disable gzip for SSL traffic.
  32. # See: https://bugs.debian.org/773332
  33. #
  34. # Read up on ssl_ciphers to ensure a secure configuration.
  35. # See: https://bugs.debian.org/765782
  36. #
  37. # Self signed certs generated by the ssl-cert package
  38. # Don't use them in a production server!
  39. #
  40. # include snippets/snakeoil.conf;
  41. listen 127.0.0.1:80 default_server;
  42. server_name domain.Name;
  43. return 301 https://$host/$request_uri;
  44. }
  45. server {
  46. #listen 443 ssl http2;
  47. #listen [::]:443 ssl;
  48. #要开启HTTP/2需要nginx版本在1.10.0以上且需要openssl版本在1.0.2以上编译
  49. #可以使用 nginx -V 检查
  50. listen 127.0.0.1:443 ssl http2;
  51. #证书配置
  52. ssl_certificate PATH;
  53. ssl_certificate_key PATH;
  54. ssl_session_cache shared:SSL:10m;
  55. ssl_session_timeout 5m;
  56. ssl_session_tickets off;
  57. #https://nginx.org/en/docs/http/ngx_http_ssl_module.html
  58. ssl_protocols TLSv1.2;
  59. ###openssl ciphers
  60. ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA'; #屏蔽不安全的加密方式
  61. ssl_prefer_server_ciphers on;
  62. # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
  63. #
  64. ###测试前请使用较少的时间 此处以从 15768000 >>> 15
  65. ###https://www.nginx.com/blog/http-strict-transport-security-hsts-and-nginx/
  66. #add_header Strict-Transport-Security max-age=15;
  67. #openssl dhparam out dhparam.pem 2048
  68. #openssl dhparam out dhparam.pem 4096
  69. #ssl_dhparam /home/acme/data/dhparam.pem;
  70. # OCSP Stapling ---
  71. # fetch OCSP records from URL in ssl_certificate and cache them
  72. #有条件就开
  73. #ssl_stapling on;
  74. #ssl_stapling_verify on;
  75. root /var/www/html;
  76. # Add index.php to the list if you are using PHP
  77. index index.html index.htm index.nginx-debian.html index.php tail.html ;
  78. server_name _;
  79. location /PATH/ {
  80. proxy_http_version 1.1;
  81. proxy_set_header Upgrade $http_upgrade;
  82. proxy_set_header Connection "upgrade";
  83. proxy_set_header Host $http_host;
  84. #host判断
  85. if ($http_host = "domain.Name" ) {
  86. #v 监听端口
  87. proxy_pass http://127.0.0.1:10086;
  88. }
  89. }
  90. # pass PHP scripts to FastCGI server
  91. #
  92. location ~ \.php$ {
  93. include snippets/fastcgi-php.conf;
  94. #
  95. # # With php-fpm (or other unix sockets):
  96. fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  97. # # With php-cgi (or other tcp sockets):
  98. # fastcgi_pass 127.0.0.1:9000;
  99. }
  100. # deny access to .htaccess files, if Apache's document root
  101. # concurs with nginx's one
  102. #
  103. #location ~ /\.ht {
  104. # deny all;
  105. #}
  106. }
  107. # Virtual Host configuration for example.com
  108. #
  109. # You can move that to a different file under sites-available/ and symlink that
  110. # to sites-enabled/ to enable it.
  111. #
  112. #server {
  113. # listen 80;
  114. # listen [::]:80;
  115. #
  116. # server_name example.com;
  117. #
  118. # root /var/www/example.com;
  119. # index index.html;
  120. #
  121. # location / {
  122. # try_files $uri $uri/ =404;
  123. # }
  124. #}