一.编写nginx服务配置
1.nginx语法格式说明:
- 大括号要成对出现
- 每一行指令后面要用分号结尾
- 每一个指令要放置在指定的区块中、
2.实现编写一个网站页面:
conf文件配置如下:
其次在站点目录创建www文件夹并新建index.html文件:
index.html的书写格式应按照html的格式进行编写,注意还要在windows的hosts文件配置域名解析
最后重启nginx即可:/application/nginx/sbin/nginx -s reload
2.实现编写多个网站页面==编写多个虚拟主机(等于一个网站)
(1).编写配置文件
1 server { 2 listen 80; 3 server_name www.etiantian.org; 4 location / { 5 root html/www; 6 index index.html index.htm; 7 } 8 } 9 server { 10 listen 80; 11 server_name bbs.etiantian.org; 12 location / { 13 root html/bbs; 14 index index.html index.htm; 15 } 16 } 17 server { 18 listen 80; 19 server_name blog.etiantian.org; 20 location / { 21 root html/blog; 22 index index.html index.htm; 23 } 24 }
(2).创建站点目录
mkdir -p /application/nginx/html/{www,bbs,blog}
(3).创建站点目录下首页文件
for name in www bbs blog; do echo "10.0.0.7 $name.etiantian.org" >/application/nginx/html/$name/index.html; done for name in www bbs blog; do cat /application/nginx/html/$name/index.html; done