1.安装nginx
brew install nginx
切换不同版本:brew switch nginx xxx
安装路径 /usr/local/etc/nginx
/usr/local/cellar/nginx/xxx
2.复制php配置在自己想要的路径 (/Users/wxy/shell/conf/nginx 为例)
cp -R /usr/local/etc/nginx /Users/wxy/shell/conf/nginx
3.带配置文件启动
sudo nginx -c /Users/wxy/shell/conf/nginx.conf
4.开启80端口权限
sudo chown root:admin /usr/local/Cellar/nginx/1.15.8/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.15.8/bin/nginx
默认Document Root: /usr/local/var/www
默认Servers:/usr/local/etc/nginx/servers/
默认启动命令:brew services start nginx
5.配置nginx.conf(/Users/wxy/shell/conf/nginx 为例)
user root owner;
#user nobody;
#user wxy staff;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /Users/wxy/tmp/nginx.pid;
error_log /Users/wxy/tmp/err-nginx.log;
events {
worker_connections 1024;
}
#daemon off;
http {
include mime.types;
default_type application/octet-stream;
#防iframe嵌套, add by wxy
add_header X-Frame-Options SAMEORIGIN always;
#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 /Users/wxy/tmp//access-nginx.log;
sendfile on;
tcp_nopush on; #与sendfile配合使用才有效果
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
#server_name localhost;
#server_name 127.0.0.1:8080;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /Users/wxy/Proj;
index index.php;
#proxy_pass http://127.0.0.1:8080;
}
#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 /Users/wxy/Proj;
fastcgi_pass 127.0.0.1:9090;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/wxy/Proj/$fastcgi_script_name;
#fastcgi_param SERVER_NAME $server_name;
include /usr/local/etc/nginx/fastcgi_params;
#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;
# }
#}
include servers/*;
}
6.配置servers(在/Users/wxy/shell/conf/nginx/servers/目录下新建 8753.conf)
server {
listen 8753;
server_name localhost;
location / {
root /Users/wxy/Proj/ace/source/ace_management;
index index.php;
}
#location ~ ^(.*)\/\.svn\/{
# deny all;
#}
location ~ \.php?$
{
fastcgi_index index.php;
fastcgi_buffer_size 512k;
fastcgi_buffers 16 512k;
fastcgi_read_timeout 300;
include /Users/wxy/shell/conf/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9090;
fastcgi_param SCRIPT_FILENAME /Users/wxy/Proj/ace/source/ace_management$fastcgi_script_name;
}
#配置图片访问
#location ~ \.(gif|jpg|jpeg|png|bmp|swf)$ {
# 默认的图片路径,也是ftp上传文件存放的路径,只要后缀是以上的都会到这个路径下搜索
# root /Users/wxy/Proj/ace/source/ace_management/web/images_cache;
#}
}
7.检查配置
nginx -c /Users/wxy/shell/conf/nginx/nginx.conf -t
8.查看nginx是否在运行
ps -ef | grep nginx
或者
ps -C nginx -o pid
或者
netstat -anp | grep :80
或者
lsof -i:80