1. server
  2. {
  3. listen 80;
  4. listen 443 ssl http2;
  5. server_name www.*.com;
  6. index index.php index.html index.htm default.php default.htm default.html;
  7. root /usr/share/nginx/html/www.*.com;
  8. if ($server_port !~ 443){
  9. rewrite ^(/.*)$ https://$host$1 permanent;
  10. }
  11. ssl_certificate /path.pem;
  12. ssl_certificate_key /path.pem;
  13. ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
  14. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
  15. ssl_prefer_server_ciphers on;
  16. ssl_session_cache shared:SSL:10m;
  17. ssl_session_timeout 10m;
  18. error_page 497 https://$host$request_uri;
  19. location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
  20. {
  21. return 404;
  22. }
  23. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  24. {
  25. expires 30d;
  26. error_log off;
  27. access_log /dev/null;
  28. }
  29. location ~ .*\.(js|css)?$
  30. {
  31. expires 12h;
  32. error_log off;
  33. access_log /dev/null;
  34. }
  35. access_log /var/log/nginx/www.*.com.access.log;
  36. error_log /var/log/nginx/www.*.com.error.log;
  37. }

静态资源

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. location / {
  5. root /usr/local/nginx/html/static;
  6. index index.html index.htm;
  7. add_header Access-Control-Allow-Origin *;
  8. add_header Access-Control-Allow-Headers X-Requested-With;
  9. add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
  10. expires 1d;
  11. }
  12. error_page 500 502 503 504 /50x.html;
  13. location = /50x.html {
  14. root /usr/share/nginx/html;
  15. }
  16. }