赞
踩
使用 brew 来安装 nginx 的命令如下:
brew install nginx
安装之后运行:
sudo nginx
在浏览器中打开如下地址:
http://localhost:8080
nginx 在 Mac 里安装完成之后它的配置文件如下:
/usr/local/etc/nginx/nginx.conf
将 nginx 的端口修改为80,在修改之前先停止 nginx :
sudo nginx -s stop
如果 Apache 在运行的话必须停止 Apache:
sudo apachectl stop
然后用 vim 打开 nginx 的配置文件:
vim /usr/local/etc/nginx/nginx.conf
接下来看到的 nginx 的配置文件如下:
server {
listen 8080;
server_name localhost;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
修改成:
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
保存配置并重新运行 nginx :
sudo nginx
在浏览器中打开如下地址:
http://localhost
如果出现* ERROR 403 Forbidden - * 不必担心, 可能是其他程序比如 skype 占用了 80 端口。
那么意味着我们要用8080端口代替80端口,我们可以使用 http://localhost:8080 来访问nginx。
用 brew 安装的 nginx 的 html 文件夹的默认位置是:
/usr/local/Cellar/nginx/1.2.3/html
注意: 将 * 1.2.3 * 修改成你自己的 nginx 版本.
默认配置是:
server {
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
我们修改成:
server {
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location / {
root /Users/to/www;
index index.html index.htm;
}
修改完之后重新运行 nginx ,nginx 就将从我们自定义的文件夹加载页面。
原文翻译自:https://coderwall.com/p/dgwwuq/installing-nginx-in-mac-os-x-maverick-with-homebrew
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。