一.以源码形式安装的nginx,没有nginx.service
二.切换到service配置目录
三.编辑nginx.service文件
四.启动测试
1.我的开始报了这个问题,说没有这个/var/cache/nginx/client_temp目录,直接创建一个就好了
2.开启/关闭
一.以源码形式安装的nginx,没有nginx.service
我的安装目录
[root@localhost nginx-1.22.0]# pwd
/usr/local/src/nginx-1.22.0
二.切换到service配置目录
[root@localhost ~]# cd /usr/lib/systemd/system/
[root@localhost system]# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx #查找出来的路径稍后会用到
三.编辑nginx.service文件
[root@localhost system]# vim nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /usr/local/src/nginx-1.22.0/conf/nginx.conf
#指定你刚才查到的目录和你的nginx配置文件
ExecStart=/usr/sbin/nginx -c /usr/local/src/nginx-1.22.0/conf/nginx.conf
#同上
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload #重载配置
四.启动测试
1.我的开始报了这个问题,说没有这个/var/cache/nginx/client_temp目录,直接创建一个就好了
[root@localhost system]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2023-08-10 10:44:29 CST; 1s ago
Docs: http://nginx.org/en/docs/
Process: 50130 ExecStartPre=/usr/sbin/nginx -t -c /usr/local/src/nginx-1.22.0/conf/nginx.conf (code=exited, status=1/FAILURE)
Aug 10 10:44:29 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
Aug 10 10:44:29 localhost.localdomain nginx[50130]: nginx: the configuration file /usr/local/src/nginx-1.22.0/conf/nginx.conf syntax is ok
Aug 10 10:44:29 localhost.localdomain nginx[50130]: nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (2: No such file or directory)
Aug 10 10:44:29 localhost.localdomain nginx[50130]: nginx: configuration file /usr/local/src/nginx-1.22.0/conf/nginx.conf test failed
Aug 10 10:44:29 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Aug 10 10:44:29 localhost.localdomain systemd[1]: Failed to start nginx - high performance web server.
Aug 10 10:44:29 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
Aug 10 10:44:29 localhost.localdomain systemd[1]: nginx.service failed.
[root@localhost nginx-1.22.0]# mkdir /var/cache/nginx/client_temp -pv
mkdir: created directory ‘/var/cache/nginx’
mkdir: created directory ‘/var/cache/nginx/client_temp’
2.开启/关闭
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# 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 Thu 2023-08-10 10:58:35 CST; 4min 2s ago
Docs: http://nginx.org/en/docs/
Process: 51071 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 51079 ExecStart=/usr/sbin/nginx -c /usr/local/src/nginx-1.22.0/conf/nginx.conf (code=exited, status=0/SUCCESS)
Process: 51076 ExecStartPre=/usr/sbin/nginx -t -c /usr/local/src/nginx-1.22.0/conf/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 51080 (nginx)
CGroup: /system.slice/nginx.service
├─51080 nginx: master process /usr/sbin/nginx -c /usr/local/src/nginx-1.22.0/c...
└─51081 nginx: worker process
Aug 10 10:58:35 localhost.localdomain systemd[1]: Starting nginx - high performance web.....
Aug 10 10:58:35 localhost.localdomain nginx[51076]: nginx: the configuration file /usr/l...k
Aug 10 10:58:35 localhost.localdomain nginx[51076]: nginx: configuration file /usr/local...l
Aug 10 10:58:35 localhost.localdomain systemd[1]: Started nginx - high performance web ...r.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl stop nginx
[root@localhost ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: http://nginx.org/en/docs/
Aug 10 10:54:04 localhost.localdomain nginx[50815]: nginx: configuration file /usr/local...l
Aug 10 10:54:04 localhost.localdomain systemd[1]: Started nginx - high performance web ...r.
Aug 10 10:58:35 localhost.localdomain systemd[1]: Stopping nginx - high performance web.....
Aug 10 10:58:35 localhost.localdomain systemd[1]: Stopped nginx - high performance web ...r.
Aug 10 10:58:35 localhost.localdomain systemd[1]: Starting nginx - high performance web.....
Aug 10 10:58:35 localhost.localdomain nginx[51076]: nginx: the configuration file /usr/l...k
Aug 10 10:58:35 localhost.localdomain nginx[51076]: nginx: configuration file /usr/local...l
Aug 10 10:58:35 localhost.localdomain systemd[1]: Started nginx - high performance web ...r.
Aug 10 11:02:42 localhost.localdomain systemd[1]: Stopping nginx - high performance web.....
Aug 10 11:02:42 localhost.localdomain systemd[1]: Stopped nginx - high performance web ...r.
Hint: Some lines were ellipsized, use -l to show in full.