Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
清理URL的Nginx配置_Url_Nginx_Server_Assets - Fatal编程技术网

清理URL的Nginx配置

清理URL的Nginx配置,url,nginx,server,assets,Url,Nginx,Server,Assets,我有一个具有以下目录结构的网站: . ├── assets ├── config ├── html ├── spec └── vendor 我使用它作为运行集成测试的开发设置,我需要一个服务器实例。我需要在html的网站根,但我需要能够链接到资产中的资产。到目前为止,这是我所拥有的,但它不起作用: server { listen 9001; server_name localhost; root /Users/hugo/src/feedback/www;

我有一个具有以下目录结构的网站:

.
├── assets
├── config
├── html
├── spec
└── vendor
我使用它作为运行集成测试的开发设置,我需要一个服务器实例。我需要在html的网站根,但我需要能够链接到资产中的资产。到目前为止,这是我所拥有的,但它不起作用:

server {
    listen       9001;
    server_name  localhost;
    root /Users/hugo/src/feedback/www;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root /Users/hugo/src/feedback/www;
        index  index.html index.htm;
    }

    location /assets/ {
        root /Users/hugo/src/feedback/assets;
    }

    #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;
    }
    # ... all the comments in the default config
}
正在提供这些页面,但它找不到任何资产。它在这里看:

http://localhost:9001/assets/bootstrap/dist/css/bootstrap.min.css
更新

您对目录结构的假设是正确的。 我将配置更改为以下内容,结果相同:

server {
    listen       9001;
    server_name  localhost;
    root /Users/hugo/src/feedback/www/html;
    index  index.html index.htm;

    location / {
    }

    location /assets/ {
        # I also tried using 'root' instead of 'alias' but same results
        alias /Users/hugo/src/feedback/www/assets;
    }
}
我看到您设置了root/Users/hugo/src/feedback/www,这对我来说意味着目录结构如下所示:

www
├── assets
├── config
├── html
├── spec
└── vendor
如果这是正确的,那么您可能需要将资产位置块修改为添加的www:


假设您实际拥有Blake Frederick认为的www设置,那么您可以研究以下内容:

server {
    listen 9001;
    server_name  localhost;
    root /Users/hugo/src/feedback/www/html;
    index  index.html index.htm;

    location / {
        # The root and index directives should typically 
        # not be in locations blocks
        # Minimum really is the server block.
        # Usually even better in http block.
    }
    location /assets/ {
        # What you need here is the alias directive
        alias /Users/hugo/src/feedback/www/assets/;
    }
}

在玩了一段时间后,我尝试了这个,它成功了

server {
    listen       9001;
    server_name  localhost;
    root /Users/hugo/src/feedback/www/html;
    index  index.html index.htm;

    location /assets/ {
        root /Users/hugo/src/feedback/www;
    }
}

我非常喜欢Dayo的答案,因为在阅读文档后,我觉得别名更适合我的工作,但不幸的是,它不起作用。

我在尝试您的解决方案后更新了答案。关于整个目录结构,您是对的。我尝试了您的解决方案,但没有结果。我在原始问题中以编辑的形式发布了更新。两个答案之间没有实质性差异。也许你在尝试应用我的建议时输入了错误的内容。我注意到,您编辑的问题遗漏了别名路径的结束斜杠,由于我记不起的原因,我始终认为有必要将其包括在内。我仔细检查了所有内容。它不适用于alias,但适用于root。我甚至尝试在别名路径的末尾添加斜杠。
server {
    listen       9001;
    server_name  localhost;
    root /Users/hugo/src/feedback/www/html;
    index  index.html index.htm;

    location /assets/ {
        root /Users/hugo/src/feedback/www;
    }
}