user skye ttxy; # User and Group, 用户及组别 worker_processes 1; # worker进程数目, 可选择具体数目或者auto error_log /usr/local/var/log/nginx/error.log warn; # 设置error日志目录, 建议设置绝对地址. pid /usr/local/var/run/nginx.pid; # 设置nginx.pid路径, 用户权限配置可读写, 建议绝对路径地址. events { worker_connections 256; # 设置每个worker进程最大连接数. } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/var/log/nginx/access.log main; # 设置访问记录access文件路径, 建议绝对路径. port_in_redirect off; # 关闭端口重定向. sendfile on; # 打开文件传输. keepalive_timeout 50; # 连接有效时长 server { listen 8080; # 监听端口 server_name localhost; # 服务器, 域名 root /Users/Kevin/Documents/Share/myweb; # 设置网站工作根目录. index index.php; # 设置默认文档, 作用域为该站点根目录下所有. location / { autoindex on; try_files $uri $uri/ /index.php?$args; # 使用wordpress时需要地址重映射.(不填写可能出现File Not Found报错) #try_files $uri = 404; # 当找不到文件是抛出404错误. } location ~ \.php$ { include /usr/local/etc/nginx/fastcgi.conf; # 配置php_fastcgi访问配置文件, 建议使用绝对路径 fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; # 设置php-fpm的back-end解析端口 include fastcgi_params; # 导入fastcgi_params参数配置 } } }
以下为fastcgi_params和fastcgi.conf默认配置
/usr/local/etc/nginx/fastcgi_params
fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200;
/usr/local/etc/nginx/
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200;