centos7安裝nginx

官網下載nginx

下載地址 http://nginx.org/en/download.html
選擇 nginx-1.13.6下載最新版本

上傳

rz -b 選擇下載好的nginx上傳到linux

解壓到 /usr/local/src目錄

tar -zxvf /opt/software/nginx-1.13.6.tar.gz -C /usr/local/src

安裝

./configure –prefix=/usr/local/nginx
安裝並指定安裝到的目錄

錯誤修改

提示下面的錯誤,是因爲缺少必要的依賴
./configure: error: C compiler cc is not found

需要安裝依賴gcc,pcre-devel,openssl,openssl-devel
yum install -y gcc pcre-devel openssl openssl-devel

如果裝了gcc還不行的話可能就是需要安裝gcc-c++
yum install gcc-c++ -y

安裝

./configure --prefix=/usr/local/nginx  
上面的命令意思是編譯 編譯完成之後需要安裝
make install 或者make進行安裝

測試是否安裝成功

啓動nginx 在usr/local/nginx/bin目錄下,有一個ngnix,執行這個可執行文件就能啓動
查看端口是否有nginx進程 netstat -ntlp |grep 80
能夠看到啓動了有關的nginx的80進程

附加:可以修改配置文件,設置反向代理和負載均衡。利用keepalived實現nginx的高可用性(相當於兩個nginx)。

httpd

安裝httpd
有關httpd的操作

systemctl start httpd.service #啓動
systemctl stop httpd.service #停止
systemctl restart httpd.service #重啓
systemctl enable httpd.service #開機啓動
systemctl disable httpd.service #開機不啓動
systemctl status httpd.service

修改端口,首先停止httpd服務,在文件中/etc/httpd/config/httpd.conf 將他的Listen監聽的端口改爲8080

動靜分離

修改nginx的配置文件,在其中加上方向代理。~表示的是大小寫敏感。符合後面的都是動態資源,要轉發的對應的proxy_pass所在的服務器。

location ~ .*.(jsp|do|action) {
proxy_cache cache_one;
proxy_cache_valid 200 304 302 5d;
proxy_cache_valid any 5d;
proxy_cache_key ‘host: server_portrequesturi;addheaderXCache upstream_cache_status from $host’;
proxy_pass 192.168.88.200:8080;
#所有靜態文件直接讀取硬盤
# root /var/lib/tomcat7/webapps/JieLiERP/WEB-INF ;
expires 30d; #緩存30天
}

負載均衡

鏈接多臺tomcats,由ngnix輪流去請求,在http{}中加入。weight是權重,如果機器性能比較好可以適當增加權重。

upstream tomcats{
    server server1:3128 weight=1;
    server server2:3128 weight=1;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章