1、安裝prce(重定向支持)和openssl(https支持,如果不需要https可以不安裝。)
yum -y install pcre*
yum -y install openssl*
2、下載nginx 1.7.8
wget http://nginx.org/download/nginx-1.7.8.tar.gz
(其實(shí) 只要 http://nginx.org/download/ 網(wǎng)站下載對(duì)應(yīng)的包 .tar.gz包)
3、解壓編譯安裝
tar -zxvf nginx-1.7.8.tar.gz
然后進(jìn)入目錄編譯安裝
cd nginx-1.7.8
./configure --prefix=/usr/local/nginx-1.5.1
--with-http_ssl_module --with-http_spdy_module
--with-http_stub_status_module --with-pcre
(開(kāi)發(fā)用 只要--prefix=/usr/local/nginx-1.5.1 為安裝目錄)
(其他配置參數(shù)參考http://nginx.org/en/linux_packages.html )
make
make install
4、開(kāi)啟nginx進(jìn)程
/usr/local/nginx-1.7.8/sbin/nginx
重啟或關(guān)閉進(jìn)程:
/usr/local/nginx-1.7.8/sbin/nginx -s reload
/usr/local/nginx-1.7.8/sbin/nginx -s stop
/usr/local/nginx-1.7.8/sbin/nginx -t (檢測(cè)配置正確與否)
5、關(guān)閉防火墻,或者添加防火墻規(guī)則就可以測(cè)試了。(防火墻配置方式)
service iptables stop
或者編輯配置文件:
vi /etc/sysconfig/iptables
添加這樣一條開(kāi)放80端口的規(guī)則后保存:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重啟服務(wù)即可:
service iptables restart
6.nginx 配置
配置文件一般在安裝目錄/conf/下 nginx.conf 文件
簡(jiǎn)單配置
在 server {
listen: xx //xx為端口號(hào)
location {
root /home/webapps 項(xiàng)目路徑
index index.html index.html //默認(rèn)首頁(yè)
}
}
備注: linux基本的軟件安裝為解壓 編譯 安裝
還有一些包管理器 如yum apt(ubuntu)