【注意】这里介绍的是基于源码下载安装的方式
下载Nginx
下载地址: http://nginx.org/en/download.html (可以下载Mainline版本,或者下载稳定版)
下载完成之后解压:
tar xvzf nginx-1.23.2.tar.gz
下载PCRE
如果直接安装Nginx,会报下面的错误,需要下载pcre:
./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.
下载地址: https://sourceforge.net/projects/pcre/files/pcre/
下载完成之后解压:
tar xvzf pcre-8.45.tar.gz
安装Nginx
-
进入Nginx目录, 然后运行配置
cd ~/Downloads/nginx-1.23.2 ./configure --with-pcre=~/Downloads/pcre-8.45
-
安装
sudo make install
-
安装完成,默认安装在目录
/usr/local/nginx
测试运行
-
进入安装目录,启动Nginx
cd /usr/local/nginx/sbin sudo ./nginx
-
浏览器访问
http://127.0.0.1
,出现“Welcome to nginx”则表示成功