mac环境brew安装nginx

安装:

brew install nginx

以下是安装完成之后打印出来的提示信息

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx

按照提示启动

brew services start nginx

查看状态:

nginx -t

如果报错

nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied)

权限问题

sudo chown -R $(whoami)  /usr/local/var/run  # 具体路径参考报错提示中的路径

重启nginx服务器

brew services stop nginx   # 停止
brew services start nginx   # 启动

提示中默认显示8080端口
http://127.0.0.1:8080/

网页中出现下面的文字,就启动成功了

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

静态服务器
在路径/usr/local/var/www下放入文件mytest.html内容如下:

<h1>hello nginx! 2018-07-10</h1>

通过链接访问测试: http://127.0.0.1:8080/mytest.html

通用配置


user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

http {

    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    client_max_body_size 20M;
    include conf.d/*.conf;
}

注意到include conf.d/*.conf; 这样就可以将conf.d这个文件夹中的所有配置文件加载进来,实现单独配置,互不影响。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值