部署nginx
下载nginx
安装nginx前置环境
- yum install gcc-c++
- yum install -y pcre pcre-devel
- yum install -y zlib zlib-devel
- yum install -y openssl openssl-devel
解压nginx安装包并编译
tar -xvf nginx-1.14.0.tar.gz
./configure && make && make install
/usr/local/nginx/sbin/nginx -t
conf/nginx.conf
sbin/nginx
sbin/nginx -s reload
配置systemctl 启动
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.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 -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start nginx.service
查看nginx的启动状态
[root@localhost conf]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2023-05-09 11:26:32 CST; 5s ago
Process: 57306 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
Process: 57303 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 57309 (nginx)
Tasks: 2
Memory: 968.0K
CGroup: /system.slice/nginx.service
├─57309 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
└─57310 nginx: worker process
5月 09 11:26:32 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
5月 09 11:26:32 localhost.localdomain nginx[57303]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
5月 09 11:26:32 localhost.localdomain nginx[57303]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
5月 09 11:26:32 localhost.localdomain systemd[1]: Started nginx - high performance web server.