首页 > 服务器    Nginx日期:2026-06-11 / 浏览

安装过程自行查询。

1.创建nginx.service

在/usr/lib/systemd/system/目录下创建nginx.service并添加以下内容:

(注:配置文件中的路径为自己nginx安装的实际路径):

vim nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

2.退出并保存文件

执行systemctl enable nginx.service使nginx开机启动

3.重启配置服务

systemctl daemon-reload

4.查看nginx服务状态

systemctl status nginx

如果nginx服务状态是关闭的

5.启动nginx.service服务并再次查看状态

systemctl start nginx
systemctl status nginx

nginx服务已经启动起来了

(注:倒数第二、三行路径是自己实际nginx的路径,更具自己实际的nginx路径在nginx.service中更改)

6.配置nginx开机自启

systemctl enable nginx

配置完成。

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章