NGINX 的 Selfoss 配置

NGINX 的 Selfoss 配置

我正在尝试使用 NGINX 配置 Selfoss。我已安装 Selfoss /usr/share/nginx/html/selfoss,我想在 上访问 Selfoss /selfoss。所以不是在子域上。

这是我的 NGINX 配置

server {
    listen 80;

    location /selfoss {
        root /usr/share/nginx/html/selfoss;
        index index.php index.html index.htm;
        try_files $uri /public/$uri /index.php$is_args$args;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        location ~* \ (gif|jpg|png) {
            expires 30d;
        }

        location ~ ^/favicons/.*$ {
            try_files $uri /data/$uri;
        }

        location ~ ^/thumbnails/.*$ {
            try_files $uri /data/$uri;
        }

        location ~* ^/(data\/logs|data\/sqlite|config\.ini|\.ht) {
            deny all;
        }

    }
}

但找不到 CSS/JS,而且 config.ini 不受保护。如何才能为 Selfoss 获得正确的 NGINX 配置。我还将 config.ini 更改为具有 {domain}/selfoss 的 base_url。

编辑:

JS 资源位置示例:

/usr/share/nginx/html/selfoss/public/js/selfoss-ui.js

NGINX 错误日志:

2017/04/06 23:00:20 [error] 4413#4413: *25 open() "/usr/share/nginx/html/404.html" failed (2: No such file or directory), client: {{client_ip}}, server: localhost, request: "GET /selfoss/all.js?v=1491477650 HTTP/1.1", host: "{{domain}}", referrer: "{{domain}}/selfoss/"

答案1

信息

Root: /usr/share/nginx/html/selfoss;
File: /usr/share/nginx/html/selfoss/public/js/selfoss-ui.js
URL:  /selfoss/js/selfoss-ui.js

分析

根据错误日志和 js 资源位置,我怀疑您错误地设置了根。

正如您所设置的,该文件的正确 URL 应该是 /public/js/selfoss-ui.js

解决方案

如果该 URL 必须保持原样,即它被您无法更改的代码引用,您有以下几种选择:

  • 将公共文件夹重命名为“selfoss”
  • 添加类似这样的位置(我不能保证这是正确的,但它至少应该让你知道如何解决它)

添加位置

location ~ /selfoss {
  alias /usr/share/nginx/html/selfoss/public;
}

该位置的一般概念是,URL 中引用 /selfoss 的任何内容都需要从文件夹 /usr/share/nginx/html/selfoss/public/ 提供,但 URL 中的 selfoss 部分不是文件系统路径的一部分。我认为别名比 root 更适合这种情况 - 请参阅此问题 / 答案

尝试其中一种解决方案,但如果您尝试 #1,则必须在尝试 #2 之前将其恢复。位置解决方案可能是最好的。如果它们不起作用,请编辑您的问题以详细描述发生了什么,并使用 curl 和日志进行演示。

相关内容