Ngnix 安裝啟動與 bind端口出錯解決
阿新 • • 發佈:2018-12-21
Ngnix 安裝
Linux系統是Centos 6.5 64位,我直接切換到root使用者下安裝
進入目錄:
下載相關元件
wget http://nginx.org/download/nginx-1.10.2.tar.gz
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
安裝c++編譯環境,如已安裝可略過
yum install gcc-c++
期間會有個輸入: y
2、安裝Nginx及相關元件
openssl安裝
cd /usr/local mkdir openssl cd /usr/software tar zxvf openssl-fips-2.0.10.tar.gz -C /usr/local/openssl/ cd /usr/local/openssl/openssl-fips-2.0.10 ./config && make && make install
pcre安裝
cd /usr/local
mkdir pcre
cd /usr/software
tar zxvf pcre-8.40.tar.gz -C /usr/local/pcre/
cd /usr/local/pcre/
cd pcre-8.40
./configure && make && make install
zlib安裝
cd /usr/local mkdir zlib cd /usr/software tar zxvf zlib-1.2.11.tar.gz -C /usr/local/zlib/ cd /usr/local/zlib/zlib-1.2.11/ ./configure && make && make install
nginx安裝
cd /usr/local
mkdir nginx
cd /usr/software
tar zxvf nginx-1.10.2.tar.gz -C /usr/local/nginx/
cd /usr/local/nginx/nginx-1.10.2/
./configure && make && make install
3、啟動Nginx
進入nginx目錄並啟動
/usr/local/nginx/sbin
./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
報錯繫結不了
進入目錄:/usr/local/nginx/nginx-1.10.2/conf
修改nginx.conf
修改nginx埠 為81
再次啟動
telnet 172.31.1.135 81
防火牆關閉
service iptables stop
新增nginx對映
vi nginx.conf
location / {
proxy_pass http://39.107.125.254:8080/springwebdemo/loginaction.do?op=tologin;
proxy_set_header Host $host:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
}
#重新整理配置
./nginx -s reload
Nginx負載均衡配置