brew update # 更新 homebrewbrew search nginx # 查看 nginx 信息brew install nginx # 安装 nginxnginx -V # 查看nginx版本及安装的本地位置nginx # 运行nginxnginx -s reload # 重新启动nginxnginx -s reopen # 重启 Nginxnginx -s stop # 停止 Nginxpkill nginx # kill只能通过进程id杀死进程,pkill可以通过进程名字杀死所有的进程
/usr/local/Cellar/nginx/1.15.9/ # 安装在这里/usr/local/var/www # 主页的文件在这个文件夹下/usr/local/etc/nginx/nginx.conf # 配置文件/usr/local/etc/nginx/servershttp://localhost:8080/#/ # 访问地址
成功:(对应的html真实路径为/usr/local/Cellar/nginx/1.15.9``/html/``index.html 指向到/usr/local/var/www/index.html)
文件夹所有权是 root wheel修改 nginx.conf 的 user root wheel;修改自定义网站代码所在目录的所有权为 chown -R root:wheel www;
配置文件参数说明
worker_processes 4; # Nginx 运行时使用的CPU核数events {worker_connections 1024; # 一个 worker进程的最大连接数}http { # Nginx用作虚拟主机时使用。每一个 server 模块生成一个虚拟主机。include mime.types; # 定义 MIME 类型和后缀名关联的文件的位置default_type application/octet-stream; # 指定 mime.types 文件中没有记述到的后缀名的处理方法log_format main '$remote_addr - $remote_user [$time_local] "$request" ' #定义日志的格式。可以选择main或者ltsv,后面定义要输出的内容。'$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';1.$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;2.$remote_user :用来记录客户端用户名称;3.$time_local :用来记录访问时间与时区;4.$request :用来记录请求的url与http协议;5.$status :用来记录请求状态;6.$body_bytes_s ent :记录发送给客户端文件主体内容大小;7.$http_referer :用来记录从那个页面链接访问过来的;8.$http_user_agent :记录客户端浏览器的相关信息;。access_log /usr/local/var/log/nginx/access.log main; # 连接日志的路径,上面指定的日志格式放在最后sendfile on; # 是否使用 OS 的 sendfile 函数来传输文件keepalive_timeout 65; # HTTP 连接的持续时间。设的太长会使无用的线程变的太多server {listen 80; # 监听端口server_name localhost; # 服务地址charset utf-8; # 编码方式access_log /usr/local/var/log/nginx/localhost.access.log main; # nginx 请求日志地址root /var/www; # 你的网站根目录location / { # 所有的请求都会走的路径index index.html index.htm index.php;try_files $uri /$uri index.php?$args; #从左边开始找指定文件是否存在}error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}location ~ \.php$ { # 正则表达式: .php文件走的路径fastcgi_pass 127.0.0.1:9000; # 走 fastcgi 路径fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; # 定义的根目录 以及 请求的脚本名include fastcgi_params; # 请求参数}location ~ /\.ht { # 当前项目的根路径deny all;}}include sites-enabled/nginx-*.conf; # 添加的文件其他虚拟主机配置}
