server { listen 80; listen 8801; client_max_body_size 20M; # 如果要开启443,请先生成你的服务器证书,若双向认证,请导入证书到你的电脑里 # listen 443 ssl; # ssl_certificate /etc/nginx/ca/ssl/certs/server.cer; # ssl_certificate_key /etc/nginx/ca/ssl/private/server.key; # ssl_client_certificate /etc/nginx/ca/ssl/certs/ca.cer; # ssl_verify_client off; # ssl_prefer_server_ciphers on; # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # ssl_ciphers HIGH:!aNULL:!MD5; #多个域名用空格分割,第一个为默认 server_name server.agent.yy163.xyz; charset UTF-8; index default.html default.htm default.php index.html index.htm index.php; # 定义根目录 set $root /var/www/agent_server/public; # 设置站点路径 root $root; # 防止目录浏览 autoindex off; #sendfile off; # 防止.htaccess文件被请求 location ~ /\.ht { access_log off; deny all; } # 跨域 set $cors_credentials ''; set $cors_content_type ''; set $cors_content_length ''; if ($http_origin ~ '.+') { set $cors_credentials 'true'; } if ($request_method = OPTIONS) { set $cors_content_type 'text/plain'; set $cors_content_length '0'; } add_header Access-Control-Allow-Origin $http_origin always; add_header Access-Control-Allow-Credentials $cors_credentials always; add_header Access-Control-Allow-Methods $http_access_control_request_method always; add_header Access-Control-Allow-Headers $http_access_control_request_headers always; add_header Content-Type $cors_content_type; add_header Content-Length $cors_content_length; if ($request_method = OPTIONS) { return 204; } location / { try_files $uri $uri/ /index.php?$query_string; } #error_page 404 /err/404.htm; # 将php类型的请求转交给fastcgi location ~ \.php$ { fastcgi_pass php80:9000; try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PHP_VALUE "open_basedir=/var/www/:/tmp/:/var/log/"; include fastcgi_params; #include fastcgi.conf; } #缓存图片周期30天 location ~* \.(jpg|jpeg|gif|png|webp|ceb)$ { access_log off; expires 30d; } #缓存js和css7天 location ~* \.(js|css|map)$ { access_log off; expires 7d; } # 访问日志: access_log /var/log/nginx/agent_server.access.log; error_log /var/log/nginx/agent_server.error.log; }