upload_php.conf 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. server {
  2. listen 80;
  3. client_max_body_size 100M;
  4. # 如果要开启443,请先生成你的服务器证书,若双向认证,请导入证书到你的电脑里
  5. # listen 443 ssl;
  6. # ssl_certificate /etc/nginx/ca/ssl/certs/server.cer;
  7. # ssl_certificate_key /etc/nginx/ca/ssl/private/server.key;
  8. # ssl_client_certificate /etc/nginx/ca/ssl/certs/ca.cer;
  9. # ssl_verify_client off;
  10. # ssl_prefer_server_ciphers on;
  11. # ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  12. # ssl_ciphers HIGH:!aNULL:!MD5;
  13. #多个域名用空格分割,第一个为默认
  14. server_name upload_php.3g.me;
  15. charset UTF-8;
  16. index default.html default.htm default.php index.html index.htm index.php;
  17. # 定义根目录
  18. set $root /var/www/upload_php/src;
  19. # 设置站点路径
  20. root $root;
  21. # 防止目录浏览
  22. autoindex off;
  23. #sendfile off;
  24. # 跨域
  25. set $cors_credentials '';
  26. set $cors_content_type '';
  27. set $cors_content_length '';
  28. if ($http_origin ~ '.+') {
  29. set $cors_credentials 'true';
  30. }
  31. if ($request_method = OPTIONS) {
  32. set $cors_content_type 'text/plain';
  33. set $cors_content_length '0';
  34. }
  35. add_header Access-Control-Allow-Origin $http_origin always;
  36. add_header Access-Control-Allow-Credentials $cors_credentials always;
  37. add_header Access-Control-Allow-Methods $http_access_control_request_method always;
  38. add_header Access-Control-Allow-Headers $http_access_control_request_headers always;
  39. add_header Content-Type $cors_content_type;
  40. add_header Content-Length $cors_content_length;
  41. if ($request_method = OPTIONS) {
  42. return 204;
  43. }
  44. # 防止.htaccess文件被请求
  45. location ~ /\.ht {
  46. deny all;
  47. }
  48. location / {
  49. try_files $uri $uri/ /index.php?$query_string;
  50. }
  51. #error_page 404 /err/404.htm;
  52. # 将php类型的请求转交给fastcgi
  53. location ~ \.php$ {
  54. fastcgi_pass php80:9000;
  55. try_files $uri =404;
  56. fastcgi_split_path_info ^(.+\.php)(.*)$;
  57. fastcgi_index index.php;
  58. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  59. fastcgi_param PHP_VALUE "open_basedir=/var/www/:/tmp/:/var/log/";
  60. include fastcgi_params;
  61. #include fastcgi.conf;
  62. }
  63. #缓存图片周期30天
  64. location ~* \.(jpg|jpeg|gif|png)$ {
  65. access_log off;
  66. expires 30d;
  67. }
  68. #缓存js和css7天
  69. location ~* \.(js|css)$ {
  70. access_log off;
  71. expires 7d;
  72. }
  73. # 访问日志:
  74. access_log /var/log/nginx/upload_php.access.log;
  75. error_log /var/log/nginx/upload_php.error.log;
  76. }