天天看點

linux 退出伺服器_linux搭建nginx服務

    最近一直在做linux伺服器部署的工作,遇到很多安裝和配置問題。下面詳細說一下nginx的安裝和配置問題(一不小心就會出錯哦)。首先你要保證你以前安裝的nginx沒有殘留,可以使用whereis nginx.conf搜尋,在進行相應的删除。在windows指令視窗登入linux伺服器,w7需要下載下傳openssh。

ssh 伺服器賬号@伺服器域名輸入密碼即可
           

1.官網下載下傳安裝包

 http://nginx.org/en/download.html,選擇适合Linux的版本,這裡選擇最新的版本,下載下傳到本地後上傳到伺服器或者centos下直接wget指令下載下傳。切換到/usr/local目錄,下載下傳軟體包。

# cd /usr/local# wget http://nginx.org/download/nginx-1.11.5.tar.gz
           

2.安裝nginx

先執行以下指令,安裝nginx依賴庫,如果缺少依賴庫,可能會安裝失敗,具體可以參考文章後面的錯誤提示資訊。

# yum install gcc-c++# yum install pcre# yum install pcre-devel# yum install zlib # yum install zlib-devel# yum install openssl# yum install openssl-devel
           

解壓安裝包

# tar -zxvf nginx-1.11.5.tar.gz
           

nginx被解壓到了/usr/local/nginx-1.11.5 目錄下(不要把壓縮包解壓到/usr/local/nginx目錄下,或者将解壓後的目錄重命名為nginx,因為nginx會預設安裝到/usr/local/nginx目錄下),切換到nginx-1.11.5/目錄

# cd /usr/local/nginx-1.11.5/
           

 執行# ./configure

# ./configure
           

該操作會檢測目前系統環境,以確定能成功安裝nginx,執行該操作後可能會出現以下幾種提示:checking for OS+Linux 3.10.0-123.el7.x86_64 x86_64

checking for C compiler ... not found

 ./configure: error: C compiler cc is not found

 如果出現以上錯誤提示資訊,執行yum install gcc-c++安裝gcc,

 ./configure: error: the HTTP rewrite module requires the PCRE library.

 You can either disable the module by using --without-http_rewrite_module

 option, or install the PCRE library into the system, or build the PCRE library

 statically from the source with nginx by using --with-pcre= option.

 如果出現上面提示,表示缺少PCRE庫

 ./configure: error: the HTTP gzip module requires the zlib library.

 You can either disable the module by using --without-http_gzip_module

 option, or install the zlib library into the system, or build the zlib library

 statically from the source with nginx by using --with-zlib= option.

如果出現以上提示,表示缺少zlib庫

如果沒有出現./configure: error提示,表示目前環境可以安裝nginx,執行make和make install編譯nginx

# make# make install
           

沒有出錯的話,表示nginx已經成功安裝完成,預設安裝位置為/usr/local/nginx,之前的/usr/local/nginx-1.11.5/可以删除掉了。如果出現cp: 'conf/koi-win' and '/usr/local/nginx/conf/koi-win' are the same file,可能是你把安裝包解壓到了/usr/local/nginx目錄,解決辦法是将該目錄重命名為其他名稱後再執行make,make install.

3.配置nginx開機啟動

切換到/lib/systemd/system/目錄,建立nginx.service檔案vim nginx.service

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

退出并儲存檔案,執行systemctl enable nginx.service使nginx開機啟動

# systemctl enable nginx.service
           

4.驗證是否安裝成功

輸入http://伺服器IP/ 如果能看到nginx的界面,就表示安裝成功了

linux 退出伺服器_linux搭建nginx服務

    我自己在安裝的時候執行make指令時會一直出現錯誤,具體的百度就可以解決了。

繼續閱讀