通过nginx实现使用浏览器对不同类型的资源访问,如html文件、图片文件和txt文本文件。

1、修改全局配置

  • 将worker进程的用户修改为nobody

  • 将worker进程数量修改为4

2、网站静态资源访问

通过域名www.test.com,可访问到nginx服务中指定的主页页面,同时可访问到指定的图片文件及txt文档。

首先创建静态资源存放的目录,在目录下放index.html ,test.txt文件

mkdir -p /data/nginx
echo “hello,index” > /data/nginx/index.html
echo “hello,Nginx” > /data/nginx/test.txt

在/etc/nginx/conf.d目录中创建关于新静态网站的配置文件static.conf,并配置以下内容:

server {
    listen       80;
    server_name  www.test.com;
    location / {
        root   /data/nginx;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /data/nginx;
    }

}