Last active
August 29, 2015 14:01
-
-
Save Teaonly/da2dd426a53a41065f36 to your computer and use it in GitHub Desktop.
How to setup nginx / php / node.js in OS X
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 如何配置nginx/php/node.js | |
在OS X下默认已经安装好PHP和 PHP-fpm (即fastcgi for PHP)两个软件,node.js和nginx则通过homebrew 安装。 | |
安装较为简单,关键是配置文件 | |
## 配置php-fpm | |
生成配置文件 | |
``` | |
cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf | |
cp /usr/local/etc/nginx/fastcgi.conf.default /usr/local/etc/nginx/fastcgi.conf | |
``` | |
修改php-fpm.conf文件,将error_log一行修改为: | |
``` | |
error_log = /usr/local/var/log/php-fpm.log | |
``` | |
修改fastcgi.conf, 将``fastcgi_param SCRIPT_FILENAME``一行删除,这个参数在nginx的配置文件里面提供。 | |
## 配置nginx的配置文件 | |
在目录``/usr/local/etc/nginx``下创建以下文件,即可使用PHP文件和对应的node.js应用: | |
``` | |
#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 80; | |
server_name localhost; | |
#charset koi8-r; | |
#access_log logs/host.access.log main; | |
location / { | |
root /Users/teaonly/Workspace/proj/VideoEditor/alpha/web; | |
index index.html; | |
} | |
location /app/ { | |
proxy_pass http://127.0.0.1:1979/; | |
} | |
#proxy the php scripts to php-fpm | |
location ~ \.php$ { | |
include /usr/local/etc/nginx/fastcgi.conf; | |
fastcgi_intercept_errors on; | |
fastcgi_param SCRIPT_FILENAME /Users/teaonly/Workspace/proj/VideoEditor/alpha/cloud/server$fastcgi_script_name; | |
fastcgi_pass 127.0.0.1:9000; | |
} | |
#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:80 | |
# | |
#location ~ \.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# 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 /scripts$fastcgi_script_name; | |
# include fastcgi_params; | |
#} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
#location ~ /\.ht { | |
# deny all; | |
#} | |
} | |
# another virtual host using mix of IP-, name-, and port-based configuration | |
# | |
#server { | |
# listen 8000; | |
# listen somename:8080; | |
# server_name somename alias another.alias; | |
# location / { | |
# root html; | |
# index index.html index.htm; | |
# } | |
#} | |
# HTTPS server | |
# | |
#server { | |
# listen 443 ssl; | |
# server_name localhost; | |
# ssl_certificate cert.pem; | |
# ssl_certificate_key cert.key; | |
# ssl_session_cache shared:SSL:1m; | |
# ssl_session_timeout 5m; | |
# ssl_ciphers HIGH:!aNULL:!MD5; | |
# ssl_prefer_server_ciphers on; | |
# location / { | |
# root html; | |
# index index.html index.htm; | |
# } | |
#} | |
} | |
``` | |
上述配置文件,生成了一个静态80端口的WWW服务,将 /app/ 方向代理到本地node.js开启的服务中,同时将所有php文件重定向到127.0.0.1:9000 的fastcgi环境中,同时规定了php文件存放的路径。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment