生產場景:實戰nginx源碼編譯安裝
阿新 • • 發佈:2018-08-11
size processes stub vim pac conn 版本號 local figure 生產場景:nginx實戰安裝
一、準備環境:
1.1 操作系統:centos 6、7
安裝常用軟件
yum install tree telnet dos2unix sysstat lrzsz nc nmap zip unzip -y
1.2 官網下載ngnx源碼包nginx-1.12.2.tar.gz,並隱藏nginx版本號和修改nginx軟件名
下載nginx源碼包nginx-1.12.2.tar.gz,並隱藏nginx版本號和修改nginx軟件名(此步驟省略)。
二、開始安裝nginx
2.1 開始安裝nginx並啟動測試
####################快速安裝nginx#############################mkdir /server/tools -p
mkdir /application
yum install openssl openssl-devel pcre pcre-devel -y
useradd www -s /sbin/nologin -M
cd /server/tools/
rz -y #上傳優化好隱藏nginx版本號和修改nginx軟件名字為Tengine的模板或者直接下載官網wget http://nginx.org/download/nginx-1.12.2.tar.gz,建議上傳優化好的模板
tar xf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --user=www --group=www --prefix=/application/nginx-1.12.2/ --with-http_stub_status_module --with-http_ssl_modulemake
make install
ln -s /application/nginx-1.12.2 /application/nginx
檢查語法並啟動nginx
/application/nginx/sbin/nginx -t /application/nginx/sbin/nginx [root@web01 nginx-1.12.2]# ps -ef|grep nginx root 25150 1 0 16:39 ? 00:00:00 nginx: master process /application/nginx-1.12.2 sbin/nginx www 25151 25150 0 16:39 ? 00:00:00 nginx: worker process root 25164 16972 0 16:41 pts/0 00:00:00 grep nginx
瀏覽器打開web02 IP查看是否可以看到nginx主頁:
http://10.0.0.8/
測試完成後關閉nginx服務。
/application/nginx/sbin/nginx -s stop
2.2 優化nginx配置文件
cd /application/nginx/conf/ cp nginx.conf{,.ori} egrep -v "^$|#" nginx.conf.default >nginx.conf #最小化nginx配置
查看默認配置文件
[root@web01 conf]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
vim nginx.conf把server標簽移除,並在http標簽中加入include extra/www.conf;和include extra/status.conf;
[root@web01 conf]# vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include extra/www.conf; include extra/status.conf; }
增加www.conf目錄及配置文件
[root@web01 conf]# pwd /application/nginx/conf [root@web01 conf]# mkdir extra [root@web01 extra]# vim extra/www.conf #添加server標簽,www1.etiantian.com用於監控www.etiantian.com是否正常 server { listen 80; server_name www.etiantian.com www1.etiantian.com; location / { root html/www; index index.html index.htm; } }
增加status.conf目錄及配置文件
生產場景:實戰nginx源碼編譯安裝