一、Nginx 安装
1、安装方式
1.1、docker-compse
目录结构:
├─docker-compose.yml
├─nginx
| ├─logs
| ├─conf
| | ├─mine.types
| | ├─nginx.conf
nginx.conf、mine.types 这些配置文件可以从官网的源码压缩包中下载。
version : '3'
services:
nginx:
image: nginx:1.21
container_name: nginx
restart: always
ports:
- "80:80"
# 如果开启 https(ssl),那么 docker 的 443 端口也要做映射
#- "443:443"
volumes:
- "./nginx/conf/nginx.conf:/etc/nginx/nginx.conf"
- "./nginx/logs:/var/log/nginx"
networks:
- node-network
networks:
node-network:
1.2、源码编译
1、下载
wget https://nginx.org/download/nginx-1.22.1.tar.gz
2、编译
# 下载依赖
yum install -y make cmake gcc gcc-c++
# 解压到 /opt/bin 目录,也可以自定义其他目录
tar -zvxf nginx-1.22.1.tar.gz -C /opt/bin/
# 检查编译条件
/opt/bin/nginx-1.22.1/configure --prefix=/usr/local/nginx
# 编译安装
make && make install
检查通过后,会有以下提示,如果检查不通过,那么提示缺少什么就安装什么。
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"
3、启动
# 启动
/usr/local/nginx/sbin/nginx
# 重启
/usr/local/nginx/sbin/nginx -s reload
# 停止
/usr/local/nginx/sbin/nginx -s stop