当前位置:   article > 正文

Mac 下使用 Homebrew 安装 Nginx_homebrew nginx log位置

homebrew nginx log位置

1、用 brew 安装 nginx

使用 brew 来安装 nginx 的命令如下:

brew install nginx
  • 1

安装之后运行:

sudo nginx
  • 1

2、测试:

在浏览器中打开如下地址:

http://localhost:8080
  • 1

3、配置nginx:

nginx 在 Mac 里安装完成之后它的配置文件如下:

/usr/local/etc/nginx/nginx.conf
  • 1

3.1 修改默认端口8080:

将 nginx 的端口修改为80,在修改之前先停止 nginx :

sudo nginx -s stop
  • 1

如果 Apache 在运行的话必须停止 Apache:

sudo apachectl stop
  • 1

然后用 vim 打开 nginx 的配置文件:

vim /usr/local/etc/nginx/nginx.conf
  • 1

接下来看到的 nginx 的配置文件如下:

server {
listen       8080;
server_name  localhost;

#access_log  logs/host.access.log  main;

location / {
    root   html;
    index  index.html index.htm;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

修改成:

listen       80;
server_name  localhost;

#access_log  logs/host.access.log  main;

location / {
    root   html;
    index  index.html index.htm;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

保存配置并重新运行 nginx :

sudo nginx
  • 1

3.2 测试修改效果:

在浏览器中打开如下地址:

http://localhost
  • 1

如果出现* ERROR 403 Forbidden - * 不必担心, 可能是其他程序比如 skype 占用了 80 端口。

那么意味着我们要用8080端口代替80端口,我们可以使用 http://localhost:8080 来访问nginx。

3.2 修改 web 应用的默认位置:

用 brew 安装的 nginx 的 html 文件夹的默认位置是:

 /usr/local/Cellar/nginx/1.2.3/html
  • 1

注意: 将 * 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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

我们修改成:

server {
listen       80;
server_name  localhost;

#access_log  logs/host.access.log  main;

location / {
    root   /Users/to/www;
    index  index.html index.htm;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

修改完之后重新运行 nginx ,nginx 就将从我们自定义的文件夹加载页面。

原文翻译自:https://coderwall.com/p/dgwwuq/installing-nginx-in-mac-os-x-maverick-with-homebrew

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/264486
推荐阅读
相关标签
  

闽ICP备14008679号