nginx自定义站点目录及简单编写开发网页内容讲解

nginx自定义站点目录及简单编写开发网页内容讲解

nginx自定义站点目录及简单编写开发网页内容讲解

nginx自定义站点目录及简单编写开发网页内容讲解

[root@web01 conf]# egrep -v "^$|#" nginx.conf.default >nginx.conf
[root@web01 conf]# pwd
/application/nginx/conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@web01 conf]# vim nginx.conf
  1 worker_processes  1;
  2 events {
  3     worker_connections  1024;
  4 }
  5 http {
  6     include       mime.types;
  7     default_type  application/octet-stream;
  8     sendfile        on;
  9     keepalive_timeout  65;
 10     server {
 11         listen       80;
 12         server_name  localhost;
 13         location / {
 14             root   html;
 15             index  index.html index.htm;
 16         }
 17         error_page   500 502 503 504  /50x.html;
 18         location = /50x.html {
 19             root   html;
 20         }
 21     }
 22 }

        把第12行修改为如下:

1
12         server_name  www.etiantian.org;

        优雅重启/application/nginx/sbin/nginx -s reload

1
2
3
4
[root@web01 conf]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful
[root@web01 conf]# /application/nginx/sbin/nginx -s reload
1
2
3
4
[root@web01 conf]# cd /application/nginx/html/
[root@web01 html]# ls
50x.html  index.html
[root@web01 html]# rm -f index.html

    编辑index.html文件,输入如下内容:

1
[root@web01 html]# vim index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
<head>
<title>老男孩教育运维28期</title>
</head>
<body>
28期最牛
<table border=1>
<tr>
<td>学号</td>
<td>姓名</td>
</tr>
<tr>
<td>01</td>
<td>力哥</td>
</tr>
<tr>
<td>02</td>
<td>亮哥</td>
</tr>
</table>
<a href="http://blog.oldboyedu.com"target=_balcnk><img src="gongli.jpg"冰冰美女</a>
</body>
</html>

        然后再到当前目录上传一张gongli.jpg的图片(图片在下面附件中)。rz -y回车上传


1
2
3
4
</html>[root@web01 html]# pwd
/application/nginx/html
[root@web01 html]# ls
50x.html  gongli.jpg  index.html

        最后打开windows ie输入地址http://10.0.0.8/ 即可打开网址。首页站点部署成功。

 nginx自定义站点目录及简单编写开发网页内容讲解

        打开windows  C:\Windows\System32\drivers\etc\hosts文件添加本地DNS解析

1
10.0.0.8 www.etiantian.org

        cmd 中ping www.etiantian.org查看解析是不是10.0.0.8ip地址,如果是直接在ie中打开网址www.etiantian.org即可。

1
2
3
4
5
6
7
8
9
10
C:\Users\Administrator>ping www.etiantian.org
正在 Ping www.etiantian.org [10.0.0.8] 具有 32 字节的数据:
来自 10.0.0.8 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.8 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.8 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.8 的回复: 字节=32 时间<1ms TTL=64
10.0.0.8 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

        nginx自定义站点目录及简单编写开发网页内容讲解