Linux 安裝 nginx

nginx下載地址:http://nginx.org/en/download.htmlhtml

1、安裝依賴軟件nginx

yum -y install gcc gcc-c++ autoconf automake makec++

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-develvim

2、安裝nginxcentos

//下載軟件tcp

下載最新的nginx-1.14.0(寫筆記時,這個版本是最新的),下載好以後,在centos系統中建立的/hone/software目錄,利用工具Xftp5,將下載好的nginx包拷貝到centos下工具

//解壓server

tar zxvf nginx-1.13.7.tar.gzhtm

//建立安裝目錄ip

mkdir -p /usr/local/nginx

//修改配置

進入 nginx-1.14.0/,能夠將文件夾重命名

./configure --prefix=/usr/local/nginx  


//安裝


make && make install


3、啓動


進入安裝目錄


cd /usr/local/nginx/sbin


啓動

./nginx    

這時候在安裝機器就能夠輸入地址查看了。

若是遠程訪問的話須要關閉防火牆或者將80端口開放,添加新端口後須要reload 防火牆。

關閉防火牆:

CentOS 7.0默認使用的是firewall做爲防火牆,這裏改成iptables防火牆步驟。

systemctl stop firewalld.service #中止firewall

systemctl disable firewalld.service #禁止firewall開機啓動

firewall-cmd --state #查看默認防火牆狀態(關閉後顯示not running,開啓後顯示running)

 

開放端口:

添加  firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,沒有此參數重啓後失效)

從新載入 firewall-cmd --reload

查看 firewall-cmd --zone= public --query-port=80/tcp

刪除 firewall-cmd --zone= public --remove-port=80/tcp --permanent

 

輸入地址後出現以下表示安裝成功了。

 

4、解決端口衝突

 

安裝後如出現上圖信息表示nginx端口與其餘軟件端口衝突,解決辦法建議修改端口。

方法1、中止佔用80端口的程序,具體自行查詢。

方法2、修改nginx.conf文件中nginx端口號。

cd /usr/local/nginx/conf 進入目錄

vim nginx.conf 打開文件

找到listen位置,將默認80端口修改成未被佔用端口。

按esc,:wq保存退出.

再次啓動nginx便可。

[html] view plain copy#access_log  logs/access.log  main;       sendfile        on;     #tcp_nopush     on;       #keepalive_timeout  0;     keepalive_timeout  65;       #gzip  on;       server {         listen      88;         server_name  localhost;           #charset koi8-r;           #access_log  logs/host.access.log  main;

相關文章
相關標籤/搜索