根位置在应用程序 url 中返回

The root location is returned in application url

我有一个 Magento 应用程序,我尝试 运行 在 CentOS 7 服务器上运行它。我能够在浏览器中访问该应用程序。但是,无法找到 cssjs 等文件,因为服务器上应用程序的根位置已添加到 url.

例如,一个文件位于:https://www.example.com/css/my_file.css 但是浏览器请求它来自:https://www.example.com/usr/share/nginx/application_name/css/my_file.css

如何获得正确的路径?

我安装了 Nginx 1.16.1 版。 Nginx 正在侦听端口 8080,因为它在侦听端口 80 的 Varnish 后面。这是虚拟主机:

server {
    listen 8080 default_server;
    server_name www.example.com;

    root  /usr/share/nginx/application_name;
    index index.php;

    location ^~ /app/ { return 403; }
    location ^~ /db/ { return 403; }
    location ^~ /dev/ { return 403; }
    location ^~ /downloader/pearlib { return 403; }
    location ^~ /downloader/template { return 403; }
    location ^~ /downloader/Maged { return 403; }
    location ~* ^/errors/.+\.xml { return 403; }
    location ^~ /includes/ { return 403; }
    location ^~ /lib/ { return 403; }
    location ^~ /media/downloadable/ { return 403; }
    location ^~ /shell/ { return 403; }
    location ^~ /var/ { return 403; }
    location ^~ /varnish/ { return 403; }
    location ^~ /vendor/ { return 403; }
    location ~ .phtml$ { return 403; }

    location / {
        index index.html index.php; ## Allow a static html file to be shown first
        try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        expires 30d; ## Assume all files are cachable
    }

    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }

    location ~ .php$ { ## Execute PHP scripts
        if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param MAGE_RUN_CODE base;
        fastcgi_param MAGE_RUN_TYPE website;
        include fastcgi_params;
        fastcgi_read_timeout 90;

    }
}

原来 Magento 的 media 文件夹对于 nginx 是不可写的,因此使用完整路径来检索文件。

设置正确的权限使其工作。