前端Nginx配置(Mac)加nginx.congif说明

文章详细介绍了如何在Mac操作系统中使用Homebrew(brew)来安装和管理nginx,包括更新brew,搜索软件,查看nginx信息,安装nginx,启动、测试、重启和停止nginx服务,以及查看和编辑配置文件。此外,还提到了创建默认首页文件和配置监听端口等基础操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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/*;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浪里个浪里个浪里个浪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值