Mac下默认安装Apache和php可以直接用的,nginx要自己配一下。
- 安装nginx
brew install nginx
一键安装
- 修改nginx配置
默认配置只能加载html文件,php文件会直接download。
因为此时nginx和php解释器没有任何关系。
配置目的:利用9000端口,将php文件的解析请求发送到php解释器,
fastcgi集中管控。
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:8080
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1:8080;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
特别注意原配置中的值为/scripts
fastcgiscriptname,需要修改为
document_root$fastcgi_script_name,
3. 配置php-fpm
复制配置文件
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
对conf文件修改:
pid=/var/run/php-fpm.pid
error_log=/var/log/php-fpm.log
【记得去掉行首注释】
4. 重启php-fpm 重启nginx
参考:
http://zhidao.baidu.com/link?url=blSUuBEHvd_b1PMPWojFmZ1v1fEGDq5JGrnki1InmEbpkD44LcDU5WrUOhrJp2j3RErKqXLS2tkoRmU12hudz_
http://outofmemory.cn/wr/?u=http%3A%2F%2Fisay.me%2F2014%2F05%2Fmac-nginx-php-fpm.html
http://blog.csdn.net/iamduoluo/article/details/38346291