一、服務器安裝部署nginx
1、下載相關組件 我是在/mall/nginx目錄下的 也可以使用 rz -y上傳
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
2、安裝c++編譯環境,如已安裝可略過
yum install gcc-c++
3、安裝Nginx及相關組件
1)openssl安裝
tar -zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install
2)pcre安裝
cd .. 回到/nginx目錄下
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure && make && make install
3)zlib安裝
cd .. 回到/nginx目錄下
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
4)nginx安裝
cd .. 回到/nginx目錄下
tar -zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install
4、啓動Nginx
先找一下nginx安裝到什麼位置上了
whereis nginx
cd /usr/local/nginx(這是上一步的結果)
進入nginx目錄並啓動
報錯了,error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory,按照下面方式解決
1.用whereis libpcre.so.1命令找到libpcre.so.1在哪裏
2.用ln -s /usr/local/lib/libpcre.so.1 /lib64命令做個軟連接就可以了
3.用sbin/nginx啓動Nginx
4.用ps -aux | grep nginx查看狀態
[root@localhost nginx]# whereis libpcre.so.1
[root@localhost nginx]# ln -s /usr/local/lib/libpcre.so.1 /lib64
[root@localhost nginx]# sbin/nginx
[root@localhost nginx]# ps -aux | grep nginx
5、打開瀏覽器輸入localhost會看到下圖,說明nginx啓動成功
注意:這裏需要配置隧道的需要配置隧道,我這裏需要配置隧道
6、將開啓的端口加入防火牆白名單中,這種方式較安全但性能也相對較差
vim /etc/sysconfig/iptables
增加下面一行代碼
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
保存退出,重啓防火牆
[root@localhost ~]# service iptables restart
7、重啓nginx
在sbin目錄下執行 ./nginx -s reload