生产场景: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 -pmkdir /applicationyum install openssl openssl-devel pcre pcre-devel -yuseradd www -s /sbin/nologin -Mcd /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.gzcd nginx-1.12.2./configure --user=www --group=www --prefix=/application/nginx-1.12.2/ --with-http_stub_status_module --with-http_ssl_modulemakemake installln -s /application/nginx-1.12.2 /application/nginx
检查语法并启动nginx
/application/nginx/sbin/nginx -t /application/nginx/sbin/nginx [[email protected] 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主页:
测试完成后关闭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配置
查看默认配置文件
[[email protected] 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;
[[email protected] 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目录及配置文件
[[email protected] conf]# pwd /application/nginx/conf [[email protected] conf]# mkdir extra [[email protected] 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目录及配置文件
原文地址:http://blog.51cto.com/sandshell/2157730
时间: 2024-10-17 11:08:44