【问题标题】:Nginx/Apache Serve Static Content proxyNginx/Apache 服务静态内容代理
【发布时间】:2013-03-20 18:40:24
【问题描述】:

我在改进 nginx 模式匹配正则表达式方面需要帮助。

# serve static files from nginx
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|wav|bmp|rtf|js|mp3|avi|mov|flv|swf)$ {
root c:/websites/www/html;
expires 1y;
}


# pass requests for dynamic content to apache listening on 8080
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 128m;
client_body_buffer_size 256k;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 32 256k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
}

Apache 在 8080 端口上运行,而 nginx 在 80 端口上运行。Apache 唯一用于处理的是 HTML、PHP 和脚本处理。 nginx 服务于其他一切。

由于我不是正则表达式的专家并且对 nginx 很陌生,我怎样才能使我的模式匹配更友好?有没有办法定义我希望 Apache 处理和服务的脚本 (html,php)?

【问题讨论】:

  • 为什么要从 apache 提供静态 html 文件?

标签: apache static nginx


【解决方案1】:

将 php/html 请求传递给 apache,然后让 nginx 处理其余部分会更容易:

# serve all remaining static file requests from nginx
location / {
  root c:/websites/www/html;
  expires 1y;
}

# pass any request uri ending with .php or .html, .htm to apache
location ~* \.(php|html|htm)$ {
  # proxy to apache
}

【讨论】:

  • 感谢您提供信息以回答上一个问题“为什么要从 apache 提供静态 html 文件?”是因为我使用 joomla 和 joomla 将 .html 类后缀添加到页面 url 由 php 生成的内容,所以我需要 apache 来处理它们。
  • 另外由于某种原因,我的 nginx 不想从我的配置开始
  • 这很奇怪。我可以将它加载到我自己的 devbox 中。如果您运行“nginx -t”,错误消息是什么?或者您的 nginx 错误日志中的错误消息是什么?在linux中,错误日志一般是/var/log/nginx/error.log。
  • 我刚刚在我的回答中复制/粘贴了您的根指令root c:/websites/www/html;。但是,文件夹名称是相对路径。所以nginx会尝试从“/etc/nginx/c:/websites/www/html”加载静态文件,是有意的吗?
  • 嗯,它是一个 Windows 服务器,所以在 Windows pc 的硬盘驱动器中的“c:/”我必须将站点移动到 nginx 文件夹中,这将使它成为“nginx/websites/www/ html;"?
猜你喜欢
  • 2011-09-17
  • 1970-01-01
  • 2011-11-06
  • 2011-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多