Nginx指向不正确的文件夹位置

Nginx指向不正确的文件夹位置,nginx,web,nginx-location,static-content,Nginx,Web,Nginx Location,Static Content,我正在尝试配置nginx以根据请求提供图像。考虑下面的配置; 站点可用/images.conf server { listen 8888; server_name localhost; location images { root html/uploads; } } ... ommitted ... http { include mime.types; default_type application

我正在尝试配置nginx以根据请求提供图像。考虑下面的配置; 站点可用/images.conf

server {
    listen       8888;
    server_name  localhost;

    location images {
        root html/uploads;
    }
}
... ommitted ...
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}

    }
    ... ommitted ...
    include sites-available/*.conf;

}
...ommitted..
nginx.conf

server {
    listen       8888;
    server_name  localhost;

    location images {
        root html/uploads;
    }
}
... ommitted ...
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}

    }
    ... ommitted ...
    include sites-available/*.conf;

}
...ommitted..
现在,当我尝试访问
http://localhost:8888/images
,它将输出
404notfound
和错误日志

2018/09/01 17:01:30[错误]10368#9796:*1 未找到“C:\nginx-1.14.0/html/images/index.html”(3:系统 找不到指定的路径),客户端:127.0.0.1,服务器:localhost, 请求:“GET/images/HTTP/1.1”,主机:“localhost:8888”


请注意,我在html中有一个名为“uploads”的文件夹。所以我希望nginx能够提供
C:\nginx-1.14.0/html/uploads/index.html
,但它没有。我不明白为什么它不会指向正确的文件夹,即
html/uploads

所有
nginx
URIs都以
/
开头,所以你的“图像”位置应该是
location/images{…}

如果URI
/images/foo
指向位于
../html/uploads/foo
的文件,则需要使用
alias
指令而不是
root
指令。有关详细信息,请参阅

例如:

location /images {
    alias html/uploads;
}