0
点赞
收藏
分享

微信扫一扫

##nginx部署安装及配置文件的解析

本版本采用1.8版本,如图:

##nginx部署安装及配置文件的解析_自定义

一、nginx安装

1、安装依赖

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
yum -y install gcc*

##nginx部署安装及配置文件的解析_自定义_02

2.下载好nginx-1.8.1.tar.gz存放到 服务器Centos 7 上的 /usr/local/ 下

3. 解压

tar zxvf nginx-1.8.1.tar.gz

##nginx部署安装及配置文件的解析_html_03

4.进行configure配置(ps:当前我在 /usr/local/ 的位置,执行以下命令)

cd /usr/local/nginx-1.8.1 && ./configure --prefix=/usr/local/nginx

5.编译安装(ps:4步骤执行后,马上进行5步骤)

make && make install

 

注安装完毕后,将在/usr/local/下看到nginx文件夹,nginx文件夹中有四个文件夹:

conf 存放配置文件

html 存放静态页面

logs 存放日志文件

sbin 执行文件

6.启动 nginx

/usr/local/nginx/sbin/nginx //启动 
/usr/local/nginx/sbin/nginx -s stop //关闭
/usr/local/nginx/sbin/nginx -s reload //重启

 7、 附带:查看启动状态 

ps -ef | grep nginx 
netstat -anptul |grep 80 //查看80端口

8、启动成功如图:

##nginx部署安装及配置文件的解析_nginx_04

9、浏览器访问即可,出现下图经典欢迎页面表示 nginx 安装成功

##nginx部署安装及配置文件的解析_html_05

ps:如果登录不到,就可能是防火墙屏蔽80端口,需要如下代码释放80端口:

firewall-cmd --permanent --znotallow=public --add-port=80/tcp 
firewall-cmd --permanent --znotallow=public --add-port=80/udp
firewall-cmd --reload

二、nginx配置

nginx 的配置文件默认位于 /usr/local/nginx/conf/ 下的 nginx.conf ##nginx部署安装及配置文件的解析_nginx_06

nginx简单的配置讲解(ngnix.conf文件),这里现在不用设置,只是做解析

vim /usr/local/nginx/conf/nginx.conf

#开启进程数 <=CPU数  
worker_processes 1;
#自定义错误日志保存位置,全局设置,默认logs/error.log
#error_log logs/error.log;
#每个进程最大连接数(最大连接=连接数x进程数)每个worker允许同时产生多少个链接,默认1024
events {
worker_connections 1024;
}
#
http {
#文件扩展名与文件类型映射表
include mime.types;
#默认文件类型
default_type application/octet-stream;
#自定义日志文件输出格式 全局设置
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#自定义全局请求日志保存位置,全局设置,默认logs/access.log, 定义格式:文件存储位置 + 日志输出格式
#access_log logs/access.log main;
#打开发送文件
sendfile on;
#连接超时时间
#keepalive_timeout 0;
keepalive_timeout 65;
#打开gzip压缩
#gzip on;
#配置虚拟主机,基于域名、ip和端口,可以配置多个server
server {
#监听端口,可以是ip:port 或者 port
listen 80;
#监听域名,可以是ip或者域名,server_name有三种匹配方式:精准匹配(www.domain.com)、通配符匹配(*.domain.com 、www.*)、正则表达式匹配(~^(?.+)\.domain\.com$)
server_name localhost;
#自定义请求日志,局部,当前server有效
#access_log logs/host.access.log main;
#错误页面及其返回地址
error_page 500 502 503 504 /50x.html;
#请求匹配,同样有精准(= /index.html)、模糊(~ index)、正则,允许配置多个location
location / { //这个/指的是安装路径的根
#返回根路径地址(相对路径:相对于/usr/local/nginx/)
root html;
#默认主页
index index.html index.htm;
}
location /html {
root html;
index index.html index.htm;
}
}
}

举报

相关推荐

0 条评论