# 下载
下载地址:http://nginx.org/en/download.html
解压源码
tar -zxvf nginx-1.24.0.tar.gz |
# 安装
安装依赖
yum -y install gcc make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel |
生成 Makefile
cd nginx-1.24.0 | |
./configure --with-http_ssl_module |
如果需要指定 openssl 源码,上面命令后加 --with-openssl=/openssl-src
,其中 /openssl-src
为 openssl 源码路径。
其他参数
参数 | 说明 |
---|---|
--prefix=PATH | 指定 nginx 安装路径(默认 /usr/local/nginx) |
--conf-path=PATH | 指定 nginx.conf 配置文件路径 |
--user=NAME | 指定 nginx 工作进程用户 |
--with-pcre | 开启 PCRE 正则表达式的支持 |
--with-http_ssl_module | 开启 SSL 的支持 |
--with-http_stub_status_module | 监控 nginx 状态 |
--with-http-realip_module | 允许改变客户端请求头中客户端 IP 地址 |
--with-file-aio | 开启 File AIO |
--add-module=PATH | 添加外部模块 |
编译安装
make | |
make install |
# 启动
cd /usr/local/nginx/sbin | |
./nginx |
查看进程
ps -ef | grep nginx | |
# 查看 pid 占用端口 | |
netstat -nap | grep pid |
查看端口
# 查看开放端口 | |
sudo firewall-cmd --zone=public --list-ports\ | |
# 开放 80 端口 | |
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent | |
# 重启防火墙 | |
sudo firewall-cmd --reload |