agent_server.conf 2.7 KB

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