配置nginx服务器来存储静态图像和html

时间:2014-01-31 04:44:19

标签: nginx

我想在我的windows7 PC中配置nginx服务器。用于存储图像和html文件。     我跟进了以下步骤:     1.我下载了nginx-1.2.9并解压缩到c:\ filder中。     2.创建了一个文件夹" data"并且在'数据"文件夹创建另外两个文件夹说" WWW"和"图像"。     3.将所有图像保存在文件夹" WWW"中的" images"文件夹。和.html文件中。     4.现在使用命令C:\ nginx-1.2.9> start nginx

启动nginx服务器
5.Made changes in nginx.conf file.`    
    #server {
    #location / {
    #    proxy_pass http://127.0.0.0:8080;
    #}

    #location /images/ {
    #    root /C:/data/images;
    # }


}

无法访问图片和html页面。     请帮我解决这个问题。我确定只在配置文件中出错了..     提前致谢,     萨蒂亚

1 个答案:

答案 0 :(得分:1)

您已对配置数据进行了评论。首先从配置文件中删除所有#。然后在服务器内使用以下代码{}

    location / {
    root data/www;
}

location /images/ {
    root data;
}

注意 - nginx根文件夹中静态文件的位置应该是(root + location)数据,文件的访问权限应该是“location”数据。例如,从第一个位置配置,静态文件应该出现在文件夹“data / WWW /”中,而在第二个位置配置中,静态文件应该出现在文件夹“data / images /”。

URL                               folder inside nginx home path
-----                            --------------------------
localhost/hello.html              data/WWW/hello.html
localhost/images/img1.png         data/images/img1.png
相关问题