nginx目录、部署站点

一、nginx软件目录

1
2
[root@yc-virtual-machine /opt/nginx1-12 11:44:02]#ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp static uwsgi_temp
  • conf 存放nginx所有配置文件的目录,主要nginx.conf
  • html 存放nginx默认站点的目录,如index.html、error.html等
  • logs 存放nginx默认日志的目录,如error.log access.log
  • sbin 存放nginx主命令的目录,sbin/nginx

Nginx主配置文件/etc/nginx/nginx.conf是一个纯文本类型的文件,整个配置文件是以区块的形式组织的。一般,每个区块以一对大括号{}来表示开始与结束。

1
2
3
4
5
6
CoreModule核心模块

user www; #Nginx进程所使用的用户
worker_processes 1; #Nginx运行的work进程数量(建议与CPU数量一致或auto)
error_log /log/nginx/error.log #Nginx错误日志存放路径
pid /var/run/nginx.pid #Nginx服务运行后产生的pid进程号

1
2
3
4
5
6
events事件模块

events {
worker_connections //每个worker进程支持的最大连接数
use epool; //事件驱动模型, epoll默认
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
http内核模块

// 公共的配置定义在http{}
http { //http层开始
...
// 使用Server配置网站, 每个Server{}代表一个网站(简称虚拟主机)
'server' {
listen 80; // 监听端口, 默认80
server_name localhost; // 提供服务的域名或主机名
access_log host.access.log // 访问日志
// 控制网站访问路径
'location' / {
root /usr/share/nginx/html; // 存放网站代码路径
index index.html index.htm; // 服务器返回的默认页面文件
}
// 指定错误代码, 统一定义错误页面, 错误代码重定向到新的Locaiton
error_page 500 502 503 504 /50x.html;
}
...
//第二个虚拟主机配置
'server' {
...
}
include /etc/nginx/conf.d/*.conf; // 包含/etc/nginx/conf.d/目录下所有以.conf结尾的文件
} // http层结束

二、部署nginx站点

nginx默认站点是Nginx目录下的html文件夹,这里可以从nginx.conf中查到

1
2
3
4
location /{
root html; #这里是默认的站点html文件夹,也就是 /opt/nginx1-12/html/文件夹下的内容
index index.html index.htm; #站点首页文件名是index.html
}

如果要部署网站业务数据,只需要把开发好的程序全放到html目录下即可

1
2
[root@yc-virtual-machine /tmp 11:34:52]#ls /opt/nginx1-12/html/
index.html jssts.jpeg lhy.mp4 man.jpg wget-log

至此,只需要通过域名/资源,即可访问

1
http://www.pyyuc.cn/index.html