安裝及配置
軟件安裝目錄爲 /usr/local 下
1.安裝gcc gcc-c++依賴包 命令:yum install -y gcc gcc-c++
2.下載編譯安裝PCRE庫 (下載之前請把目錄卻換至 /usr/local)
命令:
cd /usr/local
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
tar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make && make install
3.下載編譯安裝SSL庫 (下載之前請把目錄卻換至 /usr/local)
命令:
cd /usr/local
wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
tar -zxvf openssl-1.0.1j.tar.gz
cd openssl-1.0.1j
./config
make && make install
4.下載編譯安裝zlib依賴庫(下載之前請把目錄卻換至 /usr/local)
命令:
cd /usr/local
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make && make install
5.依賴包和環境都安裝配置好之後接下來就需要安裝nginx了 (一樣需要把目錄卻換至 /usr/local)
命令:
cd /usr/local
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
make && make install
在進行make && make install 的時候會出現stop的情況(如下圖) 如沒有出現此問題請跳過(a,b,c步驟)
解決步驟:
a.更新yum yum update 更新完成後,先刪除之前準備make的nginx包,然後重新解壓一個。
b.安裝前置庫 yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel
c.重新執行
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
make && make install
就可以成功了。
此時您的nginx就已經安裝完成了
6.啓動/停止/重啓
切換目錄:cd /usr/local/nginx
啓動:./sbin/nginx
停止:./sbin/nginx -s stop
重啓:./sbin/nginx -s reload
訪問服務器IP 就可以出現nginx index頁了。
7.403問題
問題重現:nginx進行了配置並且做了路由轉發,轉發地址爲/root/html/
重啓後再次訪問就出現了403的問題
問題查詢
通過端口查看命令查看nginx是由什麼用戶啓動的 然後再查看nginx.conf user
ps -ef | grep nginx
nginx 配置文件 /usr/local/nginx/conf/nginx.conf
如果不一致 修改爲一致 即可解決403問題
留筆記
相關參考
https://cloud.tencent.com/developer/article/1498208
https://blog.csdn.net/cailongbiaoyuli/article/details/84348866