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-content](server)

Martin Hope
Noah Broyles
Asked: 2021-12-24 07:18:10 +0800 CST

阻止 Apache2 在静态目录中执行 CGI

  • 0

我正在运行在 Ubuntu 20.04 LTS 上运行的 Apache 2 Web 服务器。我为/var/www/html目录启用了 Python CGI 处理程序,即DocumentRoot. 我想知道如何从运行 CGI for Python 文件中排除某个目录。
在我的 CGI 配置中:

<Directory "/var/www/html">
    Options +ExecCGI
    AddHandler cgi-script .py
        <IfModule mod_rewrite.c>
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteCond %{REQUEST_FILENAME}\.py -f
                RewriteRule ^(.*)$ $1.py
        </IfModule>
</Directory>

<Directory "/var/www/html/static/cdn">
        DirectoryIndex disabled
        Options +Indexes -ExecCGI
        AllowOverride None
        Require all granted
</Directory>

在/static/cdn目录中,我希望.py文件像任何其他静态文件一样被提供,而不是作为 CGI 执行。这是cdn目录树:

.
├── checkForUpdates.exe
├── checkForUpdates.py
└── findLogErrors
    ├── botCriteria.json
    ├── cleanup.json
    ├── findLogErrors.exe
    └── version.json

1 directory, 6 files

我可以根据需要在 Web 浏览器中查看目录的索引。我可以从这个目录查看或下载任何文件,除了checkForUpdates.py. 服务器没有尝试将其作为 CGI 执行,它给出了 403。权限checkForUpdates.py与其他文件相同:

nbroyles@webserver:/var/www/html/static/cdn$ ls -altr
total 15548
-rwxrwxr-x 1 www-data web 15901526 Nov 17 11:37 checkForUpdates.exe
drwxrwxr-x 7 www-data web     4096 Nov 19 11:13 ..
drwxrwxr-x 2 www-data web     4096 Dec 23 09:41 findLogErrors
drwxrwxr-x 3 www-data web     4096 Dec 23 09:49 .
-rwxrwxr-x 1 www-data web     2072 Dec 23 09:49 checkForUpdates.py

我怎样才能像查看任何.py文件一样查看文件?我确定我的配置中缺少一些简单的东西。任何帮助是极大的赞赏!.json.exe

cgi static-content apache2
  • 1 个回答
  • 81 Views
Martin Hope
Cunning
Asked: 2017-02-23 18:59:42 +0800 CST

Nginx+PHP-FPM:让php处理文件扩展名

  • 1

我正在尝试提供一个处理一些 RESTful URI 的 PHP 脚本并了解最终用户需要哪种格式的数据,我将其作为 URI 中的扩展名进行处理,例如:

example.com/foo/bar.json?q=x&a=y --> data in ajax format
example.org/foo/bar.xml?q=x&a=y  --> data in xml format

我在我的开发机器中使用了 Apache httpd + modphp,它工作得很好,但是舞台服务器使用了 CentOS + Nginx + PHP。在那里,nginx 拦截并尝试处理静态 json 文件并返回 404。

如何防止 Nginx 处理某些文件类型(例如 json、xml)并让 PHP 处理这些文件?

我的 Nginx 配置:

server {

  # listen [::]:443 ssl http2 accept_filter=dataready;  # for FreeBSD
  # listen 443 ssl http2 accept_filter=dataready;  # for FreeBSD
  # listen [::]:443 ssl http2 deferred;  # for Linux
  # listen 443 ssl http2 deferred;  # for Linux
  listen [::]:443 ssl http2;
  listen 443 ssl http2;

  # The host name to respond to
  server_name example.com;

  include h5bp/directive-only/ssl.conf;
  include ssl/conf/example.com;

  # Path for static files
  root /var/www/example.com/app/public;
  index index.php index.html index.htm;

  #Specify a charset
  charset utf-8;

  # Custom 404 page
  error_page 404 /404.html;

  # Include the basic h5bp config set
  include h5bp/basic.conf;

  # log settings
  access_log off;
  error_log  /var/log/www/example.com/nginx/error/error.log error;

  # turn off access logs and prevents logging
  # an error if robots.txt and favicon.ico are not found
  location = /favicon.ico { access_log off; log_not_found off; }
  location = /robots.txt  { access_log off; log_not_found off; }


  # check if a file or directory index file exists,
  # else pass the request to the index.php as a query parameter.
  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  # handle execution of PHP files
  # set php5-fpm socket
  # tell NGINX to proxy requests to PHP FPM via the FCGI protocol
  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass localhost:9003;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
  }

  # block access to .htaccess files
  location ~ /\.ht {
    deny all;
  }

}

更新:它终于工作了,我把 json 相关的位置放在主要/位置,并将$script_file_namejson 相关的位置更改为静态脚本名称。感谢蒂姆。

nginx static-content extension php-fpm
  • 1 个回答
  • 1910 Views
Martin Hope
ReynierPM
Asked: 2016-12-16 12:00:43 +0800 CST

静态资源无法加载,这个 Nginx 设置有什么问题?

  • 0

在运行 PHP71-FPM 和 Nginx 的 Docker 容器中,我对 Nginx 进行了以下设置:

server {
    listen      80  default_server;
    listen      81  default_server http2 proxy_protocol; ## Needed when behind HAProxy with SSL termination + HTTP/2 support
    listen      443 default_server ssl http2;

    ssl_certificate       /etc/nginx/ssl/dummy.crt;
    ssl_certificate_key   /etc/nginx/ssl/dummy.key;

    root        /data/www/demos/jqgrid;
    index       index.php index.html index.htm;

    location ~ \.php$ {
      include         fastcgi_params;
      fastcgi_pass    php-upstream;
    }

    include     /etc/nginx/conf.d/stub-status.conf;
    include     /etc/nginx/conf.d/default-*.conf;
}

访问http://localhost会显示index页面,但没有加载样式或任何 JS 文件。我无法找到阻止访问静态文件的原因。

这是主机中命令的输出ls -la(请记住,这是一个运行 PHP-FPM 和 Nginx 的 Docker 容器):

$ ls -la ~/dev/
total 96
drwxrwxr-x  11     80     80 4096 Dec 15 14:36 .
drwx------. 40 rperez rperez 4096 Dec 15 15:01 ..
drwxr-xr-x   5     80     80 4096 Mar 13  2015 css
drwxr-xr-x   7     80     80 4096 Aug  5  2015 demos
drwxr-xr-x   6     80     80 4096 Mar 26  2015 js
drwxr-xr-x   2     80     80 4096 Mar 27  2015 northwindSQL
drwxr-xr-x   4     80     80 4096 Mar 16  2015 php

权限来自 Docker(对我来说很奇怪,但我在这里打开了另一篇文章)

这些文件来自我的存储库,而这些FROM文件来自Dockerfile中的存储库。

我能得到一些帮助吗?

更新

正如@Michael 建议的那样,我检查了容器上的 Nginx 日志,我可以看到以下内容:

php71-fpm-nginx | 2016-12-15 20:02:40,483 DEBG 'nginx' stderr output:
php71-fpm-nginx | 2016/12/15 20:02:40 [error] 33#33: *46 open() "/data/www/demos/jqgrid/css/jquery-ui.css" failed (2: No such file or directory), client: 172.20.0.1, server: , request: "GET /css/jquery-ui.css HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
php71-fpm-nginx | 
php71-fpm-nginx | 2016-12-15 20:02:40,830 DEBG 'nginx' stderr output:
php71-fpm-nginx | 2016/12/15 20:02:40 [error] 33#33: *46 open() "/data/www/demos/jqgrid/css/control_icon.png" failed (2: No such file or directory), client: 172.20.0.1, server: , request: "GET /css/control_icon.png HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
php71-fpm-nginx | 

但是,如果代码相反,这怎么可能呢?

<script src="../../js/jquery.min.js" type="text/javascript"></script>
<script src="../../js/jquery-ui.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="../../css/jquery-ui.css" media="screen" />
nginx static-content centos7
  • 1 个回答
  • 81 Views
Martin Hope
sootsnoot
Asked: 2016-09-10 12:22:54 +0800 CST

如何让nginx try_files 及时获取html资源

  • 1

在实例上使用nginx1.8.1 。Amazon Linux EC2用作反向代理以支持 httpsApache在不同实例上运行。一切正常,除了这个问题。

我想提供一个静态页面nginx,以防我想Apache关闭服务器实例。所以我这样做了:

    location   / {
        try_files /site-down.html $uri @backend;
    }

因此,在关闭后端服务器之前,我在nginx服务器的根目录中创建了一个指向静态 html 文件的符号链接,如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

  <title>example.com</title>
  <style type="text/css">
  body {
    background-image:url('/images/back-soon-background.jpg');
    font-family: arial,verdana,sans-serif;
    text-align: center;
  }
  #msg {
    background-image: url('/images/back-soon-oval.png');
    background-repeat: no-repeat;
    width: 600px;
    padding-top: 140px;
    padding-left: 50px;
    padding-right: 50px;
    padding-bottom: 150px;
  }
  </style>
</head>

<body>
<div id="msg">
<h1>Sorry, the site is currently unavailable.</h1>
<h2>We expect to be back within 2 hours.</h2>
</div>
</body>
</html>

问题是,当我这样做时,页面会立即显示为 的文本内容,而没有该部分中div指定的图像。使用开发人员工具的网络选项卡,我可以看到对图像 URL 的请求,并获得 200 个状态代码。但是,如果我单击这些请求,则没有可用的预览,并且正文长度太短。重新加载页面并没有立即帮助。但是,如果我让它在那里坐一会儿,最终会出现带有图像的正确输出。如果我将浏览器直接指向,页面会立即正确显示。<style><head>Chrome/site-down.html

两者Chrome 52.0.2743.116 m的Firefox 48.0.2行为方式相同。我是新手nginx,但我无法想象为什么 try_files 中的第一个在文件存在的情况下与uri直接进入该文件的行为有什么不同。uri我错过了什么?

nginx static-content
  • 3 个回答
  • 2164 Views
Martin Hope
MvG
Asked: 2016-08-30 06:32:12 +0800 CST

允许 CORS 中的所有标头

  • 1

我想将我的 Apache 2.4 配置为以 CORS 友好的方式提供一些静态资源。我已经有以下设置:

Header always set Access-Control-Allow-Origin "*"

但是,对于最近的 Safari,这似乎还不够:

[错误]加载资源失败:请求标头字段… 不允许Access-Control-Allow-Headers。

以这种方式提到的字段包括Accept-Encodingand DNT,但我想在添加它们之后我可能还会看到Cache-Control, Originand Accept-Language,因为这些是Access-Control-Request-HeadersSafari 发送的标头中提到的字段。但是谁能告诉我 Safari 或其他浏览器现在或将来可能会为我自己或其他具有不同配置的用户请求哪些其他标头?由于我不太了解的原因,显然*不是标题的有效设置。Access-Control-Allow-Headers

那么我如何配置服务器只说“在任何地方使用这些资源,我不关心他们的 CORS”?

static-content apache-2.4 apache2 http-headers cors
  • 2 个回答
  • 3642 Views
Martin Hope
Marc Salinas
Asked: 2016-07-30 00:03:09 +0800 CST

代理静态内容仅适用于代理请求

  • 0

我有一个 apache 在“”上为一个本地应用程序提供服务/,其静态文件在“ /static”上

还有另一个应用程序mod_proxy:

ProxyPreserveHost On
ProxyPass "/example" "http://127.0.0.1:9090/"
ProxyPassReverse "/example" "http://127.0.0.1:9090/"

这个应用程序确实有自己的静态内容“ /static”但是当它来自第一个代理文件时。

¿ 有没有办法/static根据recuest的来源来为每个人提供“”?

static-content reverse-proxy apache-2.4
  • 1 个回答
  • 1141 Views
Martin Hope
Evgenii Iablokov
Asked: 2012-07-09 22:13:22 +0800 CST

Nginx 静态文件排除一个或一些文件扩展名

  • 2

我正在通过 nginx 提供一个静态站点。

    location ~* \.(avi|bin|bmp|dmg|doc|docx|dpkg|exe|flv|gif|htm|html|ico|ics|img|jpeg|jpg|m2a|m2v|mov|mp3|mp4|mpeg|mpg|msi|pdf|pkg|png|ppt|pptx|ps|rar|rss|rtf|swf|tif|tiff|txt|wmv|xhtml|xls|xml|zip)$ {
        root /var/www/html1;
        access_log off;
        expires 1d;
    }

我的目标是排除像http://connect1.webinar.ru/converter/task/. 全视图就像http://mydomain.tld/converter/task/setComplete/fid/34330/fn/7c2cfed32ec2eef6788e728fa46f7a80.ppt.swf。尽管这些 URL 以这种格式结尾,但它们不是静态的,而是伪造的脚本请求,所以我对它们有疑问。

做这个的最好方式是什么?我如何为这个 URL 添加一个排除项,或者我可以从这个 Nginx 位置的列表中排除特定的文件扩展名(.ppt.swf,pptx.swf)?

谢谢。

nginx static-content exclude
  • 3 个回答
  • 8846 Views
Martin Hope
Max
Asked: 2012-06-21 12:11:07 +0800 CST

如何确保客户在我的网站更新时更新他们的浏览器缓存?

  • 2

我正在使用HTTP 1.1 Cache-Control标头来实现客户端缓存。因为我每个月只更新一次我的网站,所以我希望CSS和JS文件可以缓存 30 天Cache-Control: max-age=2592000。问题是定义的30天周期Cache-Control与网站更新周期不一致,是从用户访问网站的那一刻开始,到30天后结束,这意味着更新可能在此期间发生,用户会使用过时的内容运行一段时间,这可能会破坏网站的呈现,例如,如果HTML和CSS不再匹配。

我如何在几天内执行客户端内容缓存,但以某种方式让用户CSS/JS在网站更新后刷新他们的文件?

我能想到的一种解决方案是,如果网站更新可以定时,max-age服务器返回的每天可以相应减少,这样无论人们什么时候访问网站,缓存期的结束都会与网站更新同步,但是每天更改服务器配置违背了我的系统管理员原则之一(一旦它运行,就不要碰它)。

http cache static-content
  • 1 个回答
  • 5794 Views
Martin Hope
Saif Bechan
Asked: 2010-04-17 08:50:09 +0800 CST

使用 Google 的 App Engine 作为静态文件的 CDN

  • 14

我正计划将我的静态文件移动到 Google 的 App Engine。我想知道这是否是个好主意。

我已经读到谷歌有可能将您的文件缓存在多个位置,我认为这是一件好事。

使用 GAE 插件在 eclipse 中设置也应该很容易。

但我仍然对它的性能表示怀疑。App Engine 的设置是否针对提供静态内容进行了优化。现在我有我的静态内容的 Nginx 服务器,App Engine 将以相同的方式执行。

使用这种方法还有其他起伏吗?

google-app-engine google-cloud-platform static-content cdn
  • 2 个回答
  • 5229 Views
Martin Hope
rizen
Asked: 2010-04-12 14:01:42 +0800 CST

apache2 mod_deflate 静态内容

  • 2

我有一台服务器每天使用 apache2 提供几百万次 JS 文件。我的一些用户希望对 JS 进行 gzip 压缩。有谁知道 apache2 mod_deflate 如何处理静态文件的压缩?它会为每个请求压缩 js(在这种情况下我会担心 cpu 负载)?如果是这样,有没有办法预压缩 JS 文件,这样 apache2 就不必为每个文件都这样做?

apache-2.2 static-content mod-deflate
  • 1 个回答
  • 1540 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