Linux下設定Nginx開機自啟

2022-07-15 10:36:06 字數 2596 閱讀 7400

1、本地環境

[root@dev ~]#cat /etc/redhat-release 

centos linux release 7.5.1804 (core)

2、在/etc/init.d建立nginx檔案,並新增如下內容

[root@dev ~]# vim /etc/init.d/nginx
指令碼內容如下:

esac3、儲存檔案後對檔案設定許可權

chmod a+x nginx
4、把指令碼新增到系統服務

chkconfig --add /etc/init.d/nginx
5、驗證系統服務

service nginx start //開戶nginx

service nginx stop //關閉nginx

6、新增到開機自啟

chkconfig nginx on
7、可能遇到的問題

systemd: starting nginx - high performance web server...

nginx: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: nginx: configuration file /etc/nginx/nginx.conf test is successful

systemd: pid file /run/nginx.pid not readable (yet?) after start.

systemd: nginx.service start operation timed out. terminating.

systemd: failed to start nginx - high performance web server.

systemd: unit nginx.service entered failed state.

systemd: nginx.service failed.

解決:修改nginx.conf中pid檔案的路徑為/var/run/nginx.pid

Nginx學習日誌(六)Linux下設定開機自啟動

最近公升級了下linux伺服器配置,重啟之後,發現要敲一堆命令列,挺麻煩的,能開啟自啟動就好了 參考資料 在linux中利用service命令新增系統服務及開機自啟動 linux下設定nginx開機自動啟動 編寫乙個指令碼,然後把它放在 etc init.d這個目錄下,再用service 指令碼名字...

Linux下設定apache開機啟動

環境 1 apache 2.2.9,安裝在 usr local apahce2下 2 red hat enterprise linux 5 第一步 cp usr local apache bin apachectl etc rc.d init.d httpd 如果有其他的版本的apache存在,也可...

Linux下設定Tomcat開機啟動

1.進入 etc rc.d init.d,新建檔案tomcat,並讓它成為可執行檔案 chmod 755 tomcat.bin bash etc rc.d init.d tomcat init script fortomcat precesses processname tomcat descrip...