Linux设置Nginx开机自动启动

Nginx 阅读: 143

配置 Nginx 开机启动

编辑文件:

vim /etc/systemd/system/nginx.service

文件内容:

[Unit]
Description=Nginx - high performance web server
After=network.target 

[Service] 
Type=forking 
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=multi-user.target

添加到开机启动:

systemctl enable nginx.service

使用systemctl控制Nginx:

# 启动
systemctl start nginx.service

# 重启
systemctl reload nginx.service

# 停止
systemctl stop nginx.service

添加 Nginx 到环境变量

打开文件:

vim /etc/profile

末尾添加两行:

PATH=$PATH:/usr/local/nginx/sbin:
export PATH

使配置生效:

source /etc/profile

版权声明:本文为博主原创文章,转载需注明来自: 洛洛の空间