Skip to content

Mac安装Nginx

安装homebrew

shell
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

安装nginx

shell
brew install nginx

查看nginx版本

shell
nginx -v

相关文件目录

text
# 文档根目录
/usr/local/var/www
# 主配置文件
/usr/local/etc/nginx/nginx.conf
# 子配置文件存放目录
/usr/local/etc/nginx/servers/

nginx配置

text
~ lingye$ cat nginx.conf
# user  root;
worker_processes 1;

events {
    worker_connections  10240;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '"$http_x_forwarded_for" $remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$upstream_addr"';

    #access_log  logs/access.log  main;

    sendfile        on;
    keepalive_timeout  65;
    # 防止加载不必要的配置,为模块化做准备
    include /usr/local/nginx/conf/conf.d/*.conf;
}

常用命令

text
nginx -c filepath	指定conf文件启动
nginx -s stop		停止
nginx -s quit		退出
nginx -s reopen		重新运行
nginx -s reload		热重启(无感)