相关文章
安装nginx
系统环境
- 操作系统:CentOS 7.9 64位
- nginx:v1.22.1
- nodejs:v14.0.0
- npm:v6.14.4
一、Nginx 安装
1、下载Nginx压缩包
1 2 3 4 5 6 7
| # cd /usr/local
# wget http://nginx.org/download/nginx-1.22.1.tar.gz
# tar -zxvf nginx-1.22.1.tar.gz
# cd nginx-1.22.1
|
2、安装依赖
1 2 3
| # yum install -y gcc gcc-c++
# yum install -y pcre-devel openssl-devel
|
3、准备安装环境
1
| # ./configure --prefix=/usr/local/nginx
|
–prefix=/usr/local/nginx 是 nginx 编译安装的目录(推荐),安装完后会在此目录下生成相关文件
如何需要支持https,追加
如何需要支持http2,追加
4、编译&安装
二、启动Nginx
1、检查配置文件
1
| # /usr/local/nginx/sbin/nginx -t
|
2、启动Nginx
1
| # /usr/local/nginx/sbin/nginx
|
3、重启Nginx
1
| # /usr/local/nginx/sbin/nginx -s reload
|
4、停止Nginx
1
| # /usr/local/nginx/sbin/nginx -s stop
|
5、添加到系统服务
1
| # vim /usr/lib/systemd/system/nginx.service
|
填写以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [Unit] Description=nginx web service Documentation=http://nginx.org/en/docs/ After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=default.target
|
相关操作如下
- 启动: systemctl start nginx
- 停止: systemctl stop nginx
- 重启: systemctl restart nginx
- 重新加载配置文件: systemctl reload nginx
- 查看nginx状态: systemctl status nginx
- 开机启动: systemctl enable nginx
6、查看nginx进程