【问题标题】:The root location is returned in application url根位置在应用程序 url 中返回
【发布时间】:2020-12-01 15:36:54
【问题描述】:

我有一个 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;

    }
}

【问题讨论】:

    标签: php nginx centos7


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多