軟體環境:centos7 nginx-1.13.7
nginx下載地址:http://nginx.org/en/download.html 一、安裝依賴軟體
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel 二、安裝nginx
//下載軟體
wget http://nginx.org/download/nginx-1.13.7.tar.gz
//解壓
tar zxvf nginx-1.13.7.tar.gz
//建立安裝目錄
mkdir -p /usr/local/nginx
//修改配置
cd nginx-1.13.7/
./configure --prefix=/usr/local/nginx
//安裝
make && make install
三、啟動
進入安裝目錄
cd /usr/local/nginx/sbin
啟動
./nginx
這時候在安裝機器就可以輸入地址查看了。
如果遠端存取的話需要關閉防火牆或者將80連接埠開放,添加新連接埠後需要reload 防火牆。 關閉防火牆:
CentOS 7.0預設使用的是firewall作為防火牆,這裡改為iptables防火牆步驟。
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
firewall-cmd --state #查看預設防火牆狀態(關閉後顯示notrunning,開啟後顯示running)
開放連接埠:
添加 firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,沒有此參數重啟後失效)
重新載入 firewall-cmd --reload
查看 firewall-cmd --zone= public --query-port=80/tcp
刪除 firewall-cmd --zone= public --remove-port=80/tcp --permanent
輸入地址後出現如下表示安裝成功了。
四、解決連接埠衝突
安裝後如出現上圖資訊表示nginx連接埠與其他軟體連接埠衝突,解決辦法建議修改連接埠。
方法一、停止佔用80連接埠的程式,具體自行查詢。
方法二、修改nginx.conf檔案中nginx連接埠號碼。
cd /usr/local/nginx/conf 進入目錄
vim nginx.conf 開啟檔案
找到listen位置,將預設80連接埠修改為未被佔用連接埠。
按esc,:wq儲存退出.
再次啟動nginx即可。
#access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 88; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main;