1. brew install nginx 2. 修改 /usr/local/etc/nginx/nginx.conf 注释掉http块里的server块 并把最后一行的 include那一行改成:#include servers/*; include /usr/local/etc/nginx/servers/*.conf; 3. /usr/local/etc/nginx/servers/下新建localhost_80.conf 内容如下: server { listen 80; root /Users/xxx/ajax; #自己项目的源码目录 server_name localhost; index index.html index.htm index.php; # 方便本地测试,开启目录浏览遍历 location / { autoindex on; # 开启目录浏览功能 autoindex_exact_size off; # 关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b autoindex_localtime on; # 开启以服务器本地时区显示文件修改日期 } location ~ \.php$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } 4. sudo nginx -t 检查配置文件有无错误 5. sudo brew services start nginx 启动nginx 监听80端口必须用sudo 6. 打开chrome 新建标签页地址栏输入 http://localhost 一切正常的话应该是显示/Users/xxx/ajax的目录内容 7. enjoy!
|
|