Nginx 安装(编译、RPM、docker)
Nginx 安装(编译、RPM、docker)
## 编译安装
1. **下载 Nginx 源码包**
```bash
wget https://alist.aawz.cc/d/zhilian/nginx%E5%AE%89%E8%A3%85%E5%8C%85/nginx-1.26.2.tar.gz?sign=vu9Y697TH8w9SpYYjYsgIBbSIlouXhDR4Y1SGGrLHPc=:0
-
安装依赖包
yum -y install pcre pcre2 pcre-devel zlib-devel gcc gcc-c++ make openssl openssl-devel wget unzip telnet net-tools vim -
配置 Nginx
./configure \ --prefix=/home/nginx \ --with-http_stub_status_module \ --with-threads \ --with-http_v2_module \ --with-stream \ --with-http_ssl_module-
如果需要整合 FastDFS,请添加以下选项:
--add-module=/usr/local/fastdfs-nginx-module/src -
如果不需要使用 SSL 证书,可以去掉:
--with-http_ssl_module
-
-
编译并安装
make && make install
RPM 安装
1. **下载 Nginx 源码包**
```bash
wget https://alist.aawz.cc/d/zhilian/nginx%E5%AE%89%E8%A3%85%E5%8C%85/nginx-1.26.1-2.el7.ngx.x86_64.rpm?sign=6s_AqD7Y4MiFsmavW3I3MmDOOUp8o2flEpNH7a95gFQ=:0
默认配置
- 默认配置路径:
/etc/nginx/nginx.conf - 默认网页文件路径:
/usr/share/nginx/html/ - 默认日志文件路径:
/var/log/nginx/
常用命令
nginx # 启动 Nginx
nginx -t # 检查配置文件
nginx -s stop # 停止 Nginx
nginx -s reload # 软重启 Nginx
nginx -c [配置文件] # 启动指定配置文件
编译安装(普通用户)
-
下载文件包
上传至服务器并解压到普通用户的家目录下。
注意:请修改nginx.conf的监听端口为 1024 以上。 -
直接编译
./configure \ --prefix=../nginx \ --with-pcre=../pcre-8.43 \ --with-zlib=../zlib-1.2.11 \ --with-openssl=../openssl-1.0.2t \ --user=abc \ --group=abc \ --with-file-aio \ --with-http_v2_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_sub_module \ --with-http_gzip_static_module \ --with-http_stub_status_module make make install
Docker 安装nginx
docker run -d -p 80:80 --name nginx --privileged --restart always -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx/conf/conf.d:/etc/nginx/conf.d -v /root/nginx/html:/usr/share/nginx/html -v /root/nginx/log:/var/log/nginx docker.io/nginx:1.25
1