mac环境brew安装nginx
  TEZNKK3IfmPf 2023年11月15日 22 0

安装:

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 nginxOr, 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这个文件夹中的所有配置文件加载进来,实现单独配置,互不影响。

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月15日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2024年05月31日   23   0   0 nginxpasswd
  TEZNKK3IfmPf   2024年04月26日   34   0   0 linuxnginxcentos
  TEZNKK3IfmPf   2024年05月31日   27   0   0 nginxpasswd
  TEZNKK3IfmPf   2024年04月19日   23   0   0 nginxTCP
  TEZNKK3IfmPf   2023年11月15日   23   0   0 nginx
  TEZNKK3IfmPf   2023年11月15日   32   0   0 nginxphp
  TEZNKK3IfmPf   2023年11月14日   31   0   0 nginxshell
  TEZNKK3IfmPf   2023年11月15日   28   0   0 nginxphp
TEZNKK3IfmPf