nginx_Domain.Name.conf 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #####本配置使用正常环境 debian9_x64 nginx_1.10.3 openssl_1.1.0f v2ray_4.2
  21. #####兼容客户端Firefox 27, Chrome 30, IE 11 on Windows 7, Edge, Opera 17, Safari 9, Android 5.0, and Java 8
  22. #####注:切勿修改<nginx.conf>中的内容,但<该文件>与<nginx.conf>中的<参数重叠>那么会<遵从前者>
  23. server {
  24. # 禁用不需要的请求方式 以下只允许 get、post
  25. if ($request_method !~ ^(POST|GET)$) {
  26. return 444;
  27. }
  28. listen 127.0.0.1:80;
  29. server_name domain.Name; #注:填写自己的域名
  30. return 301 https://$host/;
  31. }
  32. upstream v2ray {
  33. server 127.0.0.1:10086; #注:v2ray后端监听地址、端口
  34. keepalive 2176; # 链接池空闲链接数
  35. }
  36. map $http_upgrade $connection_upgrade {
  37. default upgrade;
  38. '' close;
  39. }
  40. server {
  41. #要开启 HTTP/2 注意nginx版本
  42. #可以使用 nginx -V 检查
  43. listen 127.0.0.1:443 ssl http2 backlog=1024 so_keepalive=120s:60s:10 reuseport; # backlog是nginx 监听队列 默认是511 使用命令 ss -tnl查看(Send-Q);
  44. #设置编码
  45. charset utf-8;
  46. #证书配置
  47. ssl_certificate PATH; #注:填写自己证书路径
  48. ssl_certificate_key PATH; #注:填写密钥路径
  49. ssl_session_cache shared:SSL:50m;
  50. ssl_session_timeout 1d;
  51. ssl_session_tickets off;
  52. # https://nginx.org/en/docs/http/ngx_http_ssl_module.html
  53. ssl_protocols TLSv1.2;
  54. #openssl ciphers
  55. #注:懒人配置 https://mozilla.github.io/server-side-tls/ssl-config-generator/
  56. 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';
  57. ssl_prefer_server_ciphers on;
  58. #安全设定
  59. #屏蔽请求类型
  60. if ($request_method !~ ^(POST|GET)$) {
  61. return 444;
  62. }
  63. add_header X-Frame-Options DENY;
  64. add_header X-XSS-Protection "1; mode=block";
  65. add_header X-Content-Type-Options nosniff;
  66. # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
  67. ###测试前请使用较少的时间
  68. ### https://www.nginx.com/blog/http-strict-transport-security-hsts-and-nginx/
  69. add_header Strict-Transport-Security max-age=15 always;
  70. #openssl dhparam -out dhparam.pem 2048
  71. #openssl dhparam -out dhparam.pem 4096
  72. #ssl_dhparam /home/dhparam.pem;
  73. #ssl_ecdh_curve secp384r1;
  74. # OCSP Stapling ---
  75. # fetch OCSP records from URL in ssl_certificate and cache them
  76. #ssl_stapling on;
  77. #ssl_stapling_verify on;
  78. #resolver_timeout 10s;
  79. #resolver [去掉括号并将文字改成你希望的dns服务器ip地址] valid=300s;
  80. #范例 resolver 2.2.2.2 valid=300s;
  81. root /var/www/html;
  82. # Add index.php to the list if you are using PHP
  83. index index.html index.htm index.php ;
  84. server_name domain.Name; #注: 将domain.Name 替换成你的域名
  85. location /GLMzpX/ { #注:修改路径
  86. proxy_http_version 1.1;
  87. proxy_set_header Upgrade $http_upgrade;
  88. proxy_set_header Connection $connection_upgrade; #此处与<map>对应
  89. proxy_set_header Host $http_host;
  90. # 向后端传递访客ip
  91. proxy_set_header X-Real-IP $remote_addr;
  92. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  93. sendfile on;
  94. tcp_nopush on;
  95. tcp_nodelay on;
  96. keepalive_requests 25600;
  97. keepalive_timeout 300 300;
  98. proxy_buffering off;
  99. proxy_buffer_size 8k;
  100. #后端错误重定向
  101. proxy_intercept_errors on;
  102. error_page 400 = URL; # url是一个网站地址。例如:https://www.xxxx.com/
  103. if ($http_host = "domain.Name" ) { #注: 修改 domain.Name 为自己的域名
  104. #v2ray 后端 查看上面"upstream"字段
  105. proxy_pass http://v2ray;
  106. }
  107. }
  108. }