nginx.conf 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. user www-data;
  2. worker_processes auto;
  3. pid /run/nginx.pid;
  4. daemon off;
  5. events {
  6. worker_connections 1024;
  7. use epoll;
  8. }
  9. http {
  10. include /etc/nginx/mime.types;
  11. default_type application/octet-stream;
  12. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  13. '$status $body_bytes_sent "$http_referer" '
  14. '"$http_user_agent" "$http_x_forwarded_for"';
  15. access_log /var/log/nginx/access.log main;
  16. error_log /var/log/nginx/error.log warn;
  17. sendfile on;
  18. tcp_nopush on;
  19. tcp_nodelay on;
  20. keepalive_timeout 65;
  21. types_hash_max_size 2048;
  22. client_max_body_size 55m;
  23. gzip on;
  24. gzip_min_length 1k;
  25. gzip_comp_level 4;
  26. gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
  27. upstream php-fpm {
  28. server 127.0.0.1:9000;
  29. }
  30. server {
  31. listen 80;
  32. server_name localhost;
  33. root /var/www/html/public;
  34. index index.php index.html index.htm;
  35. # 支付回调相关 - 重要
  36. location / {
  37. try_files $uri $uri/ /index.php?$query_string;
  38. }
  39. # PHP 处理
  40. location ~ \.php$ {
  41. try_files $uri =404;
  42. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  43. fastcgi_pass php-fpm;
  44. fastcgi_index index.php;
  45. include fastcgi_params;
  46. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  47. fastcgi_param PATH_INFO $fastcgi_path_info;
  48. fastcgi_read_timeout 300;
  49. }
  50. # 禁止访问隐藏文件
  51. location ~ /\. {
  52. deny all;
  53. access_log off;
  54. log_not_found off;
  55. }
  56. # 静态资源缓存
  57. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  58. expires 1y;
  59. add_header Cache-Control "public, immutable";
  60. }
  61. }
  62. }