安装
将 php
的安装目录加到系统环境变量。
http{
include mime.types;
default_type application/octet-stream;
server {
listen 10820;
server_name 127.0.0.1;
# web 目录
root D:/MyWork/Dyspace/yii-boilerplate/public;
index index.php index.html index.htm;
location / {
# 这个是针对 /a/b/c 这种形式的 uri, 见 yii
try_files $uri $uri/ /index.php?$query_string;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
server {
listen 7002;
server_name localhost;
charset utf-8;
root D:/MyWork/yifan/yifan_server;
index index.php;
#access_log logs/access.log main;
location / {
try_files $uri $uri/ /index.php$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
try_files $uri =404;
}
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
}
找到 cgi.*
开头的配置(默认9000端口), 根据需要进行修改
php
的安装目录, 运行:php-cgi.exe -b 127.0.0.1:9000
nginx
start nginx