AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[static-files](server)

Martin Hope
merdan
Asked: 2021-08-17 22:51:53 +0800 CST

来自不同文件夹的 Nginx 静态文件缓存

  • 1

问题是 nginx 不显示图像,并且在某些文件夹上显示 404 未找到。当我从配置中删除缓存时,一切正常。尝试使用此配置配置 nginx 以缓存静态文件

location ~* \.(?:css|cur|js|jpg|jpeg|webp|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|woff2|svg)$ {

                expires 1y;
                access_log off;
                add_header Cache-Control "public";
                tcp_nodelay off;
                open_file_cache max=3000 inactive=120s;
                open_file_cache_valid 45s;
                open_file_cache_min_uses 2;
                open_file_cache_errors off;
}
        # pass PHP scripts to FastCGI server
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                include fastcgi_params;
                fastcgi_intercept_errors on;
        }
  location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

这是错误日志

    2021/08/17 11:08:10 [error] 278986#278986: *3642 open() "/var/www/website/public/cache/medium/product/347/rC0dMIdOJIJNSmpKgm9pVqKVE59HKAl8SKujwxHF.jpg" failed (2: No such file or directory), client: 95.85.108.178, server: ozan.com.tm, request: "GET /cache/medium/produ
ct/347/rC0dMIdOJIJNSmpKgm9pVqKVE59HKAl8SKujwxHF.jpg HTTP/2.0", host: "www.website.tm", referrer: "https://www.website.tm/"

nginx 显示来自源的图像: https ://website.tm/storage/velocity/category_icon_path/77/5wiasmLf6hQGAsjsTV4jXsjnG0ELm5ak0rgpV7c2.png

nginx 不显示来自: https ://website.tm/cache/medium/product/353/jtTzvdT8ZmB6Lu7wFKj969Uzj0qqu1qRUt2CxEbz.jpg

cache nginx static-files
  • 1 个回答
  • 660 Views
Martin Hope
Muhammad Ebrahym
Asked: 2020-07-21 00:34:52 +0800 CST

我们正在将我们的 wordpress 迁移到静态站点。那就是在 1 个文件夹中创建超过 400,000 个文件夹。子文件夹的数量有限制吗?

  • 0

我们的 wordpress 网站已有数年历史,有许多帖子被索引并在 google 上排名很好。对于任何严重的流量,我的 wordpress 服务器都无法使用 - 即使在几轮 wordpress 优化之后也会发生这种情况。我们已经受够了 wordpress 问题,并决定迁移。

我们正在从 wordpress 迁移到静态站点以获得更好的性能,以便不会为每个请求呈现页面,并且静态 html、css、js 和图像文件可以直接由 nginx Web 服务器提供,而不是在后端访问另一台服务器。

问题是我们有超过 400,000 个帖子,每个帖子都有一个静态页面,因此我们将在其中存储相关文件,例如该帖子的 html 和图像文件。所以我们的主网络文件夹将有超过 400,000 个子文件夹。这会是Linux上的问题吗?或者这会成为我的 Web 服务器性能的问题吗?在这种情况下,托管方面有什么我应该关心的吗?

这里有没有人尝试过将 ext4 与 nginx 一起使用,并且文件夹中有大量子文件夹?真的会影响性能吗?有关于 ext4 处理大量文件夹的性能的相互矛盾的报告......我们不希望迁移增加复杂性,除非确实有必要。迁移对我们来说已经是一项艰巨的任务 :) 并且我们希望使其尽可能简单,除非存在性能下降的真正风险。有没有人在单个文件夹中使用具有大量子文件夹或文件的 nginx 网络服务器?

先感谢您。

inode wordpress ext4 cms static-files
  • 3 个回答
  • 168 Views
Martin Hope
Purlek
Asked: 2017-02-24 19:59:57 +0800 CST

全新的 Ubuntu 16.04 Nginx 配置服务于旧的静态文件

  • 2

我的域有一个非常基本的登录页面。在过去的几天里,我一直在与一个非常特殊的问题作斗争。

例如,该目录包含:

vanilla>
    ./files/
    ./index.html
    ./main_style.css

    files>
        ./back.gif
        ./back1.gif
        ./logo.png

index.html 的内容:

<!DOCTYPE html>
<html>

    <head>
        <title>Vanilla</title>
        <link rel="stylesheet" type="text/css" href="main_style.css"/>
    </head>

<body>

    <div>
        <img class="logo" src="files/logo.png" />
    </div>

</body>
</html>

main_style.css 的内容:

html {
    background-image: url("files/back1.gif");
    background-repeat: repeat;
}

img.logo {
    width: 471px;
    height: 384px;
    position: absolute;
    top: 50%;
    left:  50%;
    margin-left: -235px;
    margin-top: -192px;
}

我面临的问题是:

在重新启动或类似的事情之后,我打开网站,所有静态文件都正确加载到服务器上存在的版本。

但是,除此之外,例如,如果我对 main_style.css 进行更改,它不会反映任何更改。即使在我的浏览器中打开 main_style.css 也不会反映更改,它会显示文件的旧版本。

同样在最近,我将一张照片从 test.png 重命名为 logo.png,并在 index.html 中进行了相应的更改。index.html 文件反映了适当的更改,但是,它没有看到照片“logo.png”,并返回 404 错误……它显然在 web 根目录中,但没有提供。即便如此,我仍然可以通过 URL 访问旧照片“test.png”,即使服务器上不存在这样的文件。

我试过的:

我知道这个问题在某种程度上肯定与缓存有关,并且我在搜索中尝试了许多网络上的解决方案,但似乎都没有对我的系统产生任何影响。

我还看到,在许多情况下,这种情况可能是由 VirtualBox 或称为 Vagrant VM 的东西引起的。我的机器从来没有运行过这些东西,而我的服务器正在我办公桌下的物理 PC 上运行。

我认为这个问题可能是由于我运行了 100 多个更新引起的,因为我有一段时间没有运行我的服务器,所以我竟然从服务器备份了我的个人数据和 Web 数据并重新安装了操作系统到最新版本,然后从那里重新安装软件。

我刚刚完成,并重新配置了所有的网络软件,但可以肯定的是,它仍然有同样的问题。

重新安装操作系统后,我在机器上安装的唯一东西是:

  • openssh 服务器
  • 桑巴
  • nginx
  • mysql服务器
  • php-fpm
  • php-mysql

我读过这可以通过将nginx.conf 文件中的sendfile设置为off来解决,但这并没有解决任何问题。

我的 nginx.conf 文件和 php.ini 文件都是默认的。

nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

站点配置:

server {
        listen 80;
        root /usr/share/nginx/vanilla/;
        index index.html index.php index.htm;
        server_name www.website.com website.com;
        keepalive_timeout 10000;
        client_max_body_size 1024M;

        location / {
                try_files $uri $uri/ =404;
                #try_files $uri $uri/ /index.php?$args;
        }


        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

}
cache web-server web nginx static-files
  • 1 个回答
  • 797 Views
Martin Hope
Andrey
Asked: 2016-12-14 22:16:32 +0800 CST

Nginx 不提供大文件

  • 7

尝试下载大文件时(不确定大小是否足够,尝试下载 5Gb),连接卡住:

$ wget --verbose http://example.net/large.zip -O /dev/null
--2016-12-14 12:52:38--  http://example.net/large.zip
Resolving example.net (example.net)... 1.2.3.4
Connecting to example.net (example.net)|1.2.3.4|:80... connected.
HTTP request sent, awaiting response...

这将永远持续下去,永远我的意思是至少 10 分钟。

此类文件的 nginx 配置:

location ~* ^.+\.(css|js|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
   access_log off;
   log_not_found off;
   expires 7d;
}

小的静态文件(我的意思是小的,例如 50Mb 的)可以很好地服务。

关闭 access_log;“开启”没有帮助,此请求的日志中没有任何内容。

将文件类型从 zip 更改为另一种类型并没有帮助。

最奇怪的是,如果我开始下载并在重新启动 nginx 之后,下载开始就好了。但只有这一个。如果您在服务器重新启动后开始另一个下载,它不会以相同的方式工作。

nginx static-files
  • 3 个回答
  • 31405 Views
Martin Hope
Olivier H
Asked: 2016-08-25 07:11:54 +0800 CST

Apache HTTPD:具有代理和目录别名的虚拟主机的 URL 解析

  • 2

这是我的环境的样子:

  • REST api (django),通过端口上的 WSGI (mod_wsgi) 运行http://server:8107/api
  • API站点的静态文件(我有一些管理页面),在一个目录中,比如说/opt/wsgi/staticfiles/subdomain
  • Web 应用程序(expressjs),在 pm2/nodejs 上运行,onhttp://server:3002/

我需要将所有这些分组在端口 80 上的虚拟主机下,如下所示:

  • http://subdomain.server/api : 其余 API
  • http://subdomain.server/api/static:API站点需要的静态文件
  • http://subdomain.server/:网络应用程序

这是配置的相关部分:

<VirtualHost *:80>

    ServerName subdomain.server
    ServerAlias subdomain.server.local

    Alias /api/static/ /opt/wsgi/staticfiles/subdomain/
    <Directory /opt/wsgi/staticfiles/subdomain/ >
        Order Allow,Deny
        Allow from All
        Options -Indexes
        IndexOptions Charset=UTF-8
    </Directory>

    ProxyPass /api http://127.0.0.1:8107/api
    ProxyPassReverse /api http://127.0.0.1:8107/api

    ProxyPass / http://127.0.0.1:3002/
    ProxyPassReverse / http://127.0.0.1:3002/

</VirtualHost>

现在,当我尝试访问静态资源(例如/api/static/js/jquery.js)时,我发现 URL 不是首先由 Alias 指令解析,而是传递给 WSGI 应用程序(/api),然后显然会引发 404 错误。

重新排序指令似乎没有任何效果。

我应该改变什么以确保 HTTPD 将/api/static在其他任何事情之前服务?

*编辑*:我在 CentOS 6.5 发行版下运行 Apache HTTPD 2.2.15
virtualhost proxy httpd conf static-files
  • 1 个回答
  • 822 Views
Martin Hope
Mike Shito
Asked: 2016-06-03 08:17:29 +0800 CST

提供静态文件+反向代理时的nginx 403

  • 3

我正在尝试通过 nginx 提供节点应用程序,但首先尝试提供可能位于/public文件夹中的静态文件。我已经做了很多工作——但是在访问domain.tld/静态文件夹或索引静态文件夹时,我得到了 403;directory index of "/var/www/domain.tld/" is forbidden. 所有权限似乎都是正确的,所以我很困惑。

这是我的服务器块;

server {
    server_name domain.tld;

    location / {
        root /var/www/domain.tld/public;
        try_files $uri $uri/ @proxy;
        access_log off;
    }

    location @proxy {
        proxy_pass http://127.0.0.1:3000;
    }
 }

访问任何随机页面(包括假定的子目录)正确代理到节点应用程序。但是,对于任何现有静态目录的根 / 和根,都是 403。

有任何想法吗?

nginx reverse-proxy http-status-code-403 static-files
  • 1 个回答
  • 8699 Views
Martin Hope
user193116
Asked: 2012-06-19 11:15:49 +0800 CST

如何配置 Glassfish + NGINX 以使用 NGINX 提供静态文件?

  • 2

我有一个带有 Glassfish v3 + Nginx 设置的 EC2 ubuntu 来托管我的 java web 应用程序。此应用程序作为 WAR 文件部署到 Glassfish。NGINX 目前正在将所有请求传递给 glasshfish 应用程序服务器,包括静态图像、CSS 等 javascript 等请求。

server {
  listen  80;
  server_name whatever.com www.whatever.com;

  access_log  /var/log/nginx/whatever.com.access.log;

  location / {
    proxy_pass  http://127.0.0.1:8080/javapp/;
    proxy_pass_header Set-Cookie;
    proxy_pass_header X-Forwarded-For;
    proxy_pass_header Host;
  }

}

java glassfish nginx web-applications static-files
  • 1 个回答
  • 5707 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve