本文實例講述了CentOS6.5系統簡單安裝與配置Nginx服務器的方法。分享給大家供大家參考,具體如下:
依賴包安裝
在安裝nginx前,需要確保系統安裝了g++、gcc、openssl-devel、pcre-devel和zlib-devel軟件。安裝必須軟件:
1
2
|
[root@admin /] #yum install gcc-c++ yum -y install zlib zlib-devel openssl openssl--devel pcrepcre-devel |
檢查系統安裝的Nginx:
1
|
[root@admin local ] # find -name nginx |
卸載原有的Nginx
1
|
[root@admin /] # yum remove nginx |
安裝
將安裝包文件上傳到/usr/local中執行以下操作:
1
2
3
4
5
6
7
8
|
[root@admin local ] # cd /usr/local [root@admin local ] # tar -zxv -f nginx-1.2.6.tar.gz [root@admin local ] # rm -rf nginx-1.2.6.tar.gz [root@admin local ] # mv nginx-1.2.6 nginx [root@admin local ] # cd /usr/local/nginx [root@admin nginx] # ./configure --prefix=/usr/local/nginx [root@admin nginx] # make [root@admin nginx] # make install |
配置
1
2
3
4
5
6
|
#修改防火墻配置: [root@admin nginx-1.2.6] # vi + /etc/sysconfig/iptables #添加配置項 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -jACCEPT #重啟防火墻 [root@admin nginx-1.2.6] # service iptables restart |
啟動
1
2
3
4
5
|
#方法1 [root@admin nginx-1.2.6] # /usr/local/nginx/sbin/nginx -c/usr/local/nginx/conf/nginx.conf #方法2 [root@admin nginx-1.2.6] # cd /usr/local/nginx/sbin [root@admin sbin] # ./nginx |
停止
1
2
3
4
5
6
7
8
|
#查詢nginx主進程號 ps -ef | grep nginx #停止進程 kill -QUIT 主進程號 #快速停止 kill -TERM 主進程號 #強制停止 pkill -9 nginx |
重啟
1
|
[root@admin local ] #/usr/local/nginx/sbin/nginx -s reload |
測試
1
2
3
4
|
#測試端口 netstat Cna| grep 80 #瀏覽器中測試 http: //ip :80 |
希望本文所述對大家CentOS服務器配置有所幫助。
原文鏈接:https://blog.csdn.net/hanzheng260561728/article/details/51201093