CentOS 安裝Nginx1.14.0

原文地址:http://www.cnblogs.com/ascd-eg/p/9275441.html html

1、安裝所需環境nginx

    一、gcc 安裝
          yum install gcc-c++c++

       

    二、PCRE pcre-devel 安裝
         yum install -y pcre pcre-develvim

      
         三、zlib 安裝
         yum install -y zlib zlib-devel瀏覽器

      
         四、OpenSSL 安裝
          yum install -y openssl openssl-devel服務器

       

 

2、官網下載nginx
         一、直接下載.tar.gz安裝包,地址:https://nginx.org/en/download.htmltcp

    
       

    二、使用wget命令下載(推薦)
               wget -c https://nginx.org/download/nginx-1.14.0.tar.gzui

 

3、解壓
          tar -zxvf nginx-1.14.0.tar.gzrest

       

          


 4、配置makefile 
htm

     爲了防止  重啓nginx後  報以下異常:

                   [root@localhost sbin]# nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory  。

          推薦使用默認配置


     進入到nginx-1.14.0目錄下
              cd nginx-1.14.0  

    一、使用默認配置(我的 強烈推薦)
        ./configure

        
        二、自定義配置(不推薦)
        此方法能夠網上搜索查看,這裏我就不列出來了。
    
5、編譯安裝

   一、make
        二、make install


             

  
6、防火牆開啓80端口

   一、開啓防火牆 
             systemctl start firewalld.service


        二、防火牆開啓80端口
        firewall-cmd --zone=public --add-port=80/tcp --permanent

        


        三、重啓防火牆
             firewall-cmd --reload  或者   service firewalld restart


        四、查看端口列表
             firewall-cmd --permanent --list-port

7、查找安裝路徑
           whereis nginx


8、啓動nginx 
           cd到nginx安裝目錄的bin目錄下啓動nginx
          cd /usr/local/nginx/sbin/
          ./nginx

      
    

9、查詢nginx進程
           ps aux|grep nginx

      


10、 驗證是否安裝啓動成功  (前提:先啓動nginx)

     打開瀏覽器,輸入安裝nginx服務器的CentOS系統的IP地址,看到以下的頁面時,說明安裝啓動成功了。

     

           

 

11、 中止nginx
                ./nginx -s stop
                ./nginx -s quit


                附加說明:
                     ./nginx -s quit:此方式中止步驟是待nginx進程處理任務完畢進行中止。
                     ./nginx -s stop:此方式至關於先查出nginx進程id再使用kill命令強制殺掉進程。

 

12、設置ngnix開機自啓

        一、編輯 rc.local 文件
                   cd /etc/rc.d/
                   vim /etc/rc.d/rc.local
                   添加以下參數(此參數就是你的nginx啓動程序所在的路徑,這裏根據我的安裝的nginx位置而定,個人nginx是安裝在了/usr/local/下)
                   增長一行 /usr/local/nginx/sbin/nginx

              

              

  
    
            二、設置執行權限
                 cd /etc/rc.d/
                 chmod +x rc.local

            
    
           三、驗證開機啓動設置是否生效
                reboot(重啓系統)

        

        打開瀏覽器,輸入安裝nginx服務器的CentOS系統的IP地址,顯示以下圖的頁面,說明nginx開機自啓設置已生效。

        

相關文章
相關標籤/搜索