MAC 安装nginx

3 篇文章 0 订阅
3 篇文章 0 订阅

使用Homebrew方式进行安装

步骤:

1、更新 Homebrew

brew update

2、下载并安装 Nginx

brew install nginx

3、查看 nginx 配置信息

brew info nginx
zhanghua@Breeze ~ % brew info nginx
// 版本信息
==> nginx: stable 1.25.1 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server

// Nginx安装目录
https://nginx.org/
/usr/local/Cellar/nginx/1.25.1_1 (26 files, 2.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-08-10 at 10:48:47

// 安装来源
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@3 ✔, pcre2 ✔
==> Options
--HEAD
    Install HEAD version

// 根目录
==> Caveats
Docroot is: /usr/local/var/www

// 重点!!!nginx 的配置文件及默认启动端口 8080
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

// Nginx将在 Server 目录下加载所有文件,在这个
nginx will load all files in /usr/local/etc/nginx/servers/.

To start nginx now and restart at login:
  brew services start nginx
Or, if you don’t want/need a background service you can just run:
  /usr/local/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 11,885 (30 days), 57,023 (90 days), 84,746 (365 days)
install-on-request: 11,855 (30 days), 56,930 (90 days), 84,620 (365 days)
build-error: 3 (30 days)

4、nginx常用命令

启动
brew services start nginx

停止
brew services stop nginx

终端进入nginx 目录
cd /opt/homebrew/etc/nginx

编辑 nginx.conf 配置文件
vim nginx.conf 

编辑完成后:wq保存退出

重新加载配置文件
nginx -s reload

5、nginx配置文件 nginx.conf

#user  nobody;
worker_processes  1;

#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;
}


http {

    #http 配置

    include       mime.types;
    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;


    upstream xx{
          // 负载均衡配置
         server 127.0.0.1:8080 weight =1;
         server 127.0.0.1:8081 weight =1;
    }

    // nginx 端口 ,只要访问8080端口 就会被nginx 监听 ,如果电脑端口有冲突 可以更换端口号
    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            // 反向代理
            proxy_pass http://域名
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /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:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #证书 cert.pen和 cert.key换成证书的目录
    #    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/*;
}
  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
重新卸载和安装nginx的步骤如下: 1. 首先,进入要安装的目录。通常情况下,可以选择将nginx安装在/usr/local/src目录下。使用以下命令进入目录: ``` cd /usr/local/src/ ``` 2. 下载nginx的压缩包。可以使用以下命令下载最新版本的nginx: ``` sudo wget http://nginx.org/download/nginx-1.10.2.tar.gz ``` 3. 解压压缩包。使用以下命令解压刚刚下载的nginx压缩包: ``` sudo tar -xvf nginx-1.10.2.tar.gz ``` 4. 重命名解压后的文件夹。为了方便管理,可以将解压后的文件夹重命名为nginx,可以使用以下命令进行重命名: ``` sudo mv nginx-1.10.2 nginx ``` 5. 接下来,如果之前安装nginx,需要先卸载之前的nginx。执行以下命令进行卸载: ``` rm -rf /etc/nginx/ rm -rf /usr/sbin/nginx rm /usr/share/man/man1/nginx.1.gz sudo apt-get remove nginx* ``` 6. 最后,运行nginx。首先,我们需要找到nginx的配置文件,可以使用以下命令进行搜索: ``` sudo find / -name nginx.conf ``` 以上是重新卸载和安装nginx的步骤。请按照上述步骤进行操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [linux下nginx全部卸载,重新安装并运行](https://blog.csdn.net/changyana/article/details/123452943)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值