Linux環境下配置Nginx開機自啟動

2021-10-01 12:33:00 字數 2663 閱讀 9820

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

以上部分將nginx新增到了系統服務,下面將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

linux環境下nginx對映配置

root屬性指定的值是要加入到最終路徑的,將root的路徑替換掉host的部分 得到的url其實就是資源的真實儲存路徑。與root屬性不同的是alias 的路徑會代替掉或者說拋棄掉,反正就是不用之前的url了,url直接變成了alias的路徑。rewrite 語法格式 rewrite flag fl...

windows環境下Nginx配置

作為乙個前端,在工作的時候肯定會遇到這樣的實際問題,就是要讓別人看到跑在你自己機子上localhost的頁面。這個時候就需要靠apache和iis幫忙了,當然現在有許多整合好的mysql和apache等框架,例如我自己本來就是使用很簡單的speedamp,小白式操作就ok了。但是之前一直久聞ngin...

CentOS 下Nginx環境配置

linux版本 centos7 64位 nginx依賴元件 gcc openssl devel pcre devel zlib devel 快速安裝依賴 yum install gcc openssl devel pcre devel zlib devel 解壓 tar zxvf nginx 1.9...