MacOS 安装Nginx,记录安装过程及nginx编译过程

MacOS 安装Nginx,记录安装过程及nginx编译过程

MacOS安装nginx的方式有几种,可以通过brew install nginx的方式,也可以向本次记录的一样,采用下载nginx的tar.gz包,在本地进行编译。

1 下载nginx

wget https://nginx.org/download/nginx-1.18.0.tar.gz
tar zxf nginx-1.18.0.tar.gz 
cd nginx-1.18.0

下载后进入到nginx的源码目录,

 $ ls
CHANGES    LICENSE    auto       configure  html       src
CHANGES.ru README     conf       contrib    man

2 编译nginx

编译配置选项在这个名为configure的文件里面,里面设置了各种参数

ll
total 1520
-rw-r--r--   1 1001  1001   296K  4 21  2020 CHANGES
-rw-r--r--   1 1001  1001   451K  4 21  2020 CHANGES.ru
-rw-r--r--   1 1001  1001   1.4K  4 21  2020 LICENSE
-rw-r--r--   1 1001  1001    49B  4 21  2020 README
drwxr-xr-x  25 1001  1001   800B  4 21  2020 auto
drwxr-xr-x  11 1001  1001   352B  4 21  2020 conf
-rwxr-xr-x   1 1001  1001   2.4K  4 21  2020 configure
drwxr-xr-x   6 1001  1001   192B  4 21  2020 contrib
drwxr-xr-x   4 1001  1001   128B  4 21  2020 html
drwxr-xr-x   3 1001  1001    96B  4 21  2020 man
drwxr-xr-x   9 1001  1001   288B  4 21  2020 src

在目录中直接运行,如果先在一台机器上安装多个nginx,这时就需要修改configure文件。

case ".$NGX_PREFIX" in
    .)
        NGX_PREFIX=${NGX_PREFIX:-/usr/local/nginx1.21.6}
        have=NGX_PREFIX value="\"$NGX_PREFIX/\"" . auto/define
    ;;

    .!)
sudo ./configure
checking for OS
 + Darwin 20.6.0 x86_64
checking for C compiler ... found
 + using Clang C compiler
 + clang version: 13.0.0 (clang-1300.0.29.30)

看生成的的后续打印情况,里面有没有提示缺少依赖

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

提示缺少依赖,先根据提示情况进行安装

$ brew install pcre
==> Downloading https://ghcr.io/v2/homebrew/core/pcre/manifests/8.45
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/pcre/blobs/sha256:fb2fefbe12327
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Pouring pcre--8.45.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/pcre/8.45: 204 files, 5.8MB
==> `brew cleanup` has not been run in the last 30 days, running now...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /Users/bird/Library/Logs/Homebrew/ncurses... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/apr-util... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/utf8proc... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/lz4... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/ca-certificates... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/gettext... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/apr... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/pcre2... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/openssl@1.1... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/fish... (64B)
Removing: /Users/bird/Library/Logs/Homebrew/subversion... (64B)
Pruned 0 symbolic links and 2 directories from /usr/local

再次执行configure后

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

没有报错了,提示了nginx的安装位置等一些信息。

3 make 编译与安装

$ sudo make && make install

按一下输出信息,确保正确编译安装

sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
		-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
		-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
		-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
		< man/nginx.8 > objs/nginx.8
/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile install
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
		|| mkdir -p '/usr/local/nginx/sbin'
mkdir: /usr/local/nginx/sbin: Permission denied
make[1]: *** [install] Error 1
make: *** [install] Error 2

这里一直输出没想到最后还是因为权限问题install失败了,加上sudo安装成功,这里要说明一下,我是make成功了,但是执行make install因为权限问题失败,后面单独运行的sudo make install

$ ls
conf html logs sbin

运行nginx

$ ./nginx

在/usr/local/nginx/sbin/下直接运行有提示没有权限,我这里采用的是setUID的方式,就是给二进制文件运行权限,

$ chmod u+s /usr/loacl/nginx/sbin/nginx

执行后可以直接

$ ./nginx

可以使用下面的命令查询是否运行成功

ps -ef |grep nginx
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在macOS安装nginx,你可以按照以下步骤进行操作: 1. 首先,请确保已经安装了Homebrew。如果没有安装,请参考常见问题部分的指南来安装Homebrew。 2. 使用以下命令安装nginx:brew install nginx。这将会下载并安装nginx。 3. 安装完成后,可以使用nginx -v命令来查看已安装nginx版本。 4. 要启动nginx,可以使用命令nginx。 5. 如果想要关闭nginx,可以使用命令nginx -s stop。 6. 如果需要重新加载nginx配置文件,可以使用命令nginx -s reload。 7. 在安装过程中,可能会遇到端口被占用的问题。如果出现类似于"bind() to 0.0.0.0:80 failed (48: Address already in use)"的错误提示,这意味着端口80已经被其他进程占用了。 #### 引用[.reference_title] - *1* *2* [关于MacOSNginx安装及配置](https://blog.csdn.net/BSSMWYT/article/details/122767822)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [Mac 安装 Nginx](https://blog.csdn.net/speedwalkman/article/details/130723412)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值