1.更新brew brew update
2. 查询要安装的软件是否存在 brew search nginx
3. 查询本机nginx情况 brew info nginx 如果出现一下情况:
4. Not installed — nginx在本地还未安装
5. From — nginx的下载地址 /usr/local/var/www — Docroot默认路径
6. 8080 — 为 /usr/local/etc/nginx/nginx.conf 配置文件中被配置的默认端口,nginx运行时不需要加sudo
7.nginx将在/usr/local/etc/nginx/servers/目录中加载所有文件
安装nginx:
brew install nginx
open /usr/local/Cellar/nginx。 打开文件位置
/usr/local/opt/nginx/bin/nginx 启动
/usr/local/opt/nginx/bin/nginx -t 启动测试
/usr/local/opt/nginx/bin/nginx -s reload 重启
/usr/local/opt/nginx/bin/nginx -s stop 停止
cat /usr/local/opt/nginx/nginx.conf 查看nginx配置
ps -ef |grep nginx 查看有多个进程
sudo ps -ef | grep nginx | grep -v grep | awk ‘{print $2}’ | xargs kill -9 关闭所有的nginx
如果你的根目录没有首页索引文件,可以手动创建一个
cd /usr/local/var/www/ //进入到www目录下
touch index.html //创建一个新的index.html文件
vim index.html //编辑该文件 ;
按esc键,输入:wq退出编辑并保存
Mac安装:
一起执行:
brew tap denji/nginx
brew install nginx-full --with-rtmp-module
brew info nginx-full 查看安装位置
#user nobody;
worker_processes 1; #worker进程数量
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024; #每个worker进程支持最大的连接数
}
http {
include mime.types; # nginx 支持的媒体类型文库文件
default_type application/octet-stream; # 默认的媒体类型
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on; # 开启高效传输模式
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; #链接超时
#gzip on;
server {
listen 80; 提供的默认服务器端口 80
server_name localhost; # 提供服务器的域名主机名
#charset koi8-r;
#access_log logs/host.access.log main;
location / { # 第一个location 区块开始
root html; # 站点的根目录 相当于nginx的安装目录
index index.html index.htm; # 默认的首页文件 多个可以用空格分开
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; # 出现对应的http状态码时,使用50x。html回应客户
location = /50x.html {
root html; # 指定对应的站点目录
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:9090;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include servers/*;
}