欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解基于CentOS 7配置Nginx自啟動(dòng)

 更新時(shí)間:2018年03月30日 08:41:36   作者:Leshami  
這篇文章主要介紹了詳解基于CentOS 7配置Nginx自啟動(dòng),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

Nginx是廣為流行的輕量級(jí)Web服務(wù)器軟件。它開源,短小精悍,簡單易用,深受廣大互聯(lián)網(wǎng)企業(yè)以及IT運(yùn)維人員所喜愛。很多時(shí)候,我們?cè)谏a(chǎn)環(huán)境基于編譯方式安裝Nginx后,Nginx需要手工配置自啟動(dòng)服務(wù),以確保服務(wù)器異常宕機(jī)后自動(dòng)重啟該服務(wù)。以下描述的是基于CentOS 7下來配置自啟動(dòng)服務(wù),供大家參考。

一、yum 安裝方式Nginx自啟動(dòng)

當(dāng)前環(huán)境

[root@node142 ~]# more /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

查看是否保護(hù)nginx rpm包

[root@node142 ~]# rpm -qa|grep nginx
nginx-mod-http-geoip-1.12.2-2.el7.x86_64
nginx-1.12.2-2.el7.x86_64
nginx-filesystem-1.12.2-2.el7.noarch
nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64
nginx-mod-stream-1.12.2-2.el7.x86_64
nginx-mod-http-perl-1.12.2-2.el7.x86_64
nginx-mod-http-image-filter-1.12.2-2.el7.x86_64
nginx-all-modules-1.12.2-2.el7.noarch
nginx-mod-mail-1.12.2-2.el7.x86_64

查看是否存在相應(yīng)的服務(wù),如下,有nginx.service

[root@node142 ~]# systemctl list-unit-files |grep nginx
nginx.service               disabled

將其配置為自動(dòng)

[root@node142 ~]# systemctl enable nginx.service

查看nginx.service文件

[root@node142 ~]# more /lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

上述配置文件中的內(nèi)容和官網(wǎng)提供的一模一樣

https://www.nginx.com/resources/wiki/start/topics/examples/systemd/

二、編譯安裝后的自啟動(dòng)配置

由于是編譯安裝,因此,對(duì)于這個(gè)自啟動(dòng)的腳本我們需要自行配制。

具體則是參考上面的鏈接或者上面給出的nginx.service文件內(nèi)容。

然后將其保存為 /lib/systemd/system/nginx.service。

看下面的例子

# more /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

# ps -ef|grep nginx
root  10092 10014 0 16:23 pts/0  00:00:00 grep --color=auto nginx
root  20791  1 0 Mar20 ?    00:00:00 nginx: master process ./sbin/nginx -c /u01/app/nginx/nginx.conf
nobody 20792 20791 0 Mar20 ?    00:00:44 nginx: worker process
nobody 20793 20791 0 Mar20 ?    00:00:42 nginx: worker process
nobody 20794 20791 0 Mar20 ?    00:00:50 nginx: worker process
nobody 20795 20791 0 Mar20 ?    00:00:44 nginx: worker process
nobody 20796 20791 0 Mar20 ?    00:00:43 nginx: worker process
nobody 20797 20791 0 Mar20 ?    00:00:43 nginx: worker process
nobody 20798 20791 0 Mar20 ?    00:00:37 nginx: worker process
nobody 20799 20791 0 Mar20 ?    00:00:48 nginx: worker process
nobody 20800 20791 0 Mar20 ?    00:00:04 nginx: cache manager process
# 

無相應(yīng)的rpm包,如下查詢,此處為編譯安裝

# rpm -qa|grep nginx

也沒有添加相應(yīng)的自啟動(dòng)服務(wù)

# systemctl list-unit-files |grep nginx

nginx版本

# /u01/app/nginx/sbin/nginx -v
nginx version: nginx/1.8.1

獲取nginx編譯模塊,然后查看諸如pid,二進(jìn)制位置并記錄以便修改啟動(dòng)文件

# /u01/app/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/u01/app/nginx --sbin-path=/u01/app/nginx/sbin/nginx 
--conf-path=/u01/app/nginx/nginx.conf --error-log-path=/u01/app/nginx/log/error.log 
--http-log-path=/u01/app/nginx/log/access.log --pid-path=/u01/app/nginx/nginx.pid 
--lock-path=/u01/app/nginx/nginx.lock --http-client-body-temp-path=/u01/app/nginx/client_temp 
--http-proxy-temp-path=/u01/app/nginx/proxy_temp 
--http-fastcgi-temp-path=/u01/app/nginx/fastcgi_temp 
--http-uwsgi-temp-path=/u01/app/nginx/uwsgi_temp --http-scgi-temp-path=/u01/app/nginx/scgi_temp
--user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module 
--with-http_addition_module --with-http_sub_module --with-http_dav_module
--with-http_flv_module --with-http_mp4_module --with-http_gunzip_module 
--with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module 
--with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module
--with-file-aio --with-http_spdy_module --with-ipv6

下面我們生成一個(gè)新的nginx.service文件

# vim /lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/u01/app/nginx/nginx.pid
ExecStartPre=/u01/app/nginx/sbin/nginx -t
ExecStart=/u01/app/nginx/sbin/nginx 
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

下面我們先手工停止nginx

# /u01/app/nginx/sbin/nginx -s stop

配置自啟動(dòng)

# systemctl enable nginx.service

使用systemctl工具啟動(dòng)nginx服務(wù)

# systemctl start nginx.service

# systemctl status nginx.service
● nginx.service - The NGINX HTTP and reverse proxy server
 Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
 Active: active (running) since Thu 2018-03-29 16:37:47 CST; 6s ago
 Process: 10588 ExecStart=/u01/app/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Process: 10586 ExecStartPre=/u01/app/nginx/sbin/nginx -t (code=exited, status=0/SUCCESS)
Main PID: 10590 (nginx)
 CGroup: /system.slice/nginx.service
     ├─10590 nginx: master process /u01/app/nginx/sbin/nginx
     ├─10591 nginx: worker process # Author : Leshami
     ├─10592 nginx: worker process # Blog : https://blog.csdn.net/leshami
     ├─10593 nginx: worker process
     ├─10594 nginx: worker process
     ├─10595 nginx: worker process
     ├─10596 nginx: worker process
     ├─10597 nginx: worker process
     ├─10598 nginx: worker process
     ├─10599 nginx: cache manager process
     └─10600 nginx: cache loader process

Mar 29 16:37:47 ydq-std systemd[1]: Starting The NGINX HTTP and reverse proxy server...
Mar 29 16:37:47 ydq-std nginx[10586]: nginx: the configuration file /u01/app/nginx/nginx.conf syntax is ok
Mar 29 16:37:47 ydq-std nginx[10586]: nginx: configuration file /u01/app/nginx/nginx.conf test is successful
Mar 29 16:37:47 ydq-std systemd[1]: Started The NGINX HTTP and reverse proxy server.

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • nginx配置多個(gè)站點(diǎn)共用80端口的解決方法

    nginx配置多個(gè)站點(diǎn)共用80端口的解決方法

    這篇文章主要介紹了nginx配置多個(gè)站點(diǎn)共用80端口的解決方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-06-06
  • Nginx location(正則)使用

    Nginx location(正則)使用

    這篇文章主要介紹了Nginx location(正則)使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • Ubuntu+Nginx+Mysql+Php+Zend+eaccelerator安裝配置文字版

    Ubuntu+Nginx+Mysql+Php+Zend+eaccelerator安裝配置文字版

    把我架設(shè)lnmp網(wǎng)站的過程寫出來,希望對(duì)想架設(shè)網(wǎng)站的朋友有所幫助,如有更好的辦法請(qǐng)?zhí)岢鰜?/div> 2012-02-02
  • Nginx配置WebSocket反向代理的實(shí)現(xiàn)示例

    Nginx配置WebSocket反向代理的實(shí)現(xiàn)示例

    本文主要介紹了Nginx配置WebSocket反向代理的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-08-08
  • nginx-proxy-manager初次登錄報(bào)錯(cuò)502?bad?gateway解決

    nginx-proxy-manager初次登錄報(bào)錯(cuò)502?bad?gateway解決

    這篇文章主要給大家介紹了關(guān)于nginx-proxy-manager初次登錄報(bào)錯(cuò)502?bad?gateway的解決辦法,502?Bad?Gateway服務(wù)器作為網(wǎng)關(guān)或者代理時(shí),為了完成請(qǐng)求訪問下一個(gè)服務(wù)器,但該服務(wù)器返回了非法的應(yīng)答,需要的朋友可以參考下
    2024-04-04
  • Nginx如何集成到Windows服務(wù)

    Nginx如何集成到Windows服務(wù)

    文章介紹了如何在Windows 11上將Nginx配置為系統(tǒng)服務(wù),并提供了一個(gè)詳細(xì)的步驟指南,包括下載和配置Winsw工具,以及安裝和刪除Nginx服務(wù)的方法
    2024-12-12
  • nginx處理http請(qǐng)求實(shí)例詳解

    nginx處理http請(qǐng)求實(shí)例詳解

    這篇文章主要介紹了nginx處理http請(qǐng)求實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • Nginx實(shí)現(xiàn)404錯(cuò)誤自動(dòng)跳轉(zhuǎn)到首頁的配置過程

    Nginx實(shí)現(xiàn)404錯(cuò)誤自動(dòng)跳轉(zhuǎn)到首頁的配置過程

    當(dāng)用戶在訪問網(wǎng)站的過程中遇到404錯(cuò)誤時(shí),通常情況下應(yīng)該顯示一個(gè)友好的錯(cuò)誤頁面,而不是僅僅顯示一個(gè)簡單的錯(cuò)誤提示,在Nginx中,可以通過配置來實(shí)現(xiàn)404錯(cuò)誤自動(dòng)跳轉(zhuǎn)到首頁的功能,下面將詳細(xì)介紹如何進(jìn)行配置,需要的朋友可以參考下
    2023-12-12
  • nginx實(shí)現(xiàn)TCP反向代理的示例代碼

    nginx實(shí)現(xiàn)TCP反向代理的示例代碼

    本文主要介紹了nginx實(shí)現(xiàn)TCP反向代理的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-01-01
  • 詳解ngx_cache_purge _proxy_cache指令使用

    詳解ngx_cache_purge _proxy_cache指令使用

    本文主要介紹了詳解ngx_cache_purge _proxy_cache指令使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07

最新評(píng)論