【发布时间】:2017-12-03 21:34:27
【问题描述】:
所以,基本上我在 Docker php7-fpm 容器中运行 Joomla,然后我有一个 nginx 容器,其中 joomla.conf 文件定义如下:
#https://docs.joomla.org/nginx
server {
listen 8081;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
server_name php-docker.local;
root /usr/src/joomla;
index index.php index.html index.htm default.html default.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
location ~ \.php$ {
fastcgi_pass joomla:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
#include /etc/nginx/fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
这按预期工作...转到 http://:8081 会正确加载所有内容。
现在,8081 只是暂时暴露在 nginx 容器中,我真正想做的是设置一个反向代理,这样 http:///joomla 将成为最终端点。
为此,我正在努力使用以下 conf 文件:
server{
listen 80;
server_name _;
location /joomla/ {
proxy_pass http://localhost:8081/;
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
}
}
发生的情况是 HTML 被正确提供,但是,没有任何资产。这是因为 Joomla 中的 URL 是由 JURI 类生成的,该类似乎依赖于 $request_uri,当它似乎到达 Joomla 时,它已经丢失了。
因此,对文件、脚本或 css 的每个链接或引用都呈现如下:
代替:
但是,当我访问第二组 URL 时,我可以毫无问题地访问链接/资产……当然,再一次,没有正确呈现图像、模板、js 或链接。
除非出现问题,否则我不喜欢碰 joomla.conf,至于 site.conf,我只想翻译 URI 段以将请求映射到其他应用程序,例如:
/joomla -> localhost:8081
/phpbb -> localhost:8082
/someapp -> localhost:8083
【问题讨论】:
-
您是否尝试过从浏览器访问这个? :
http:///joomla/(以 / 结尾)。 -
您的 nginx 配置不会影响 Joomla 生成链接的方式。如果您面向 nginx 的客户端仅将
/joomla/转发到上游 Joomla nginx,那么它将永远不会通过/images/headers/maple.jpg或/login。如果您将始终在面向 nginx 的客户端上通过/joomla/访问 Joomla,那么您唯一的选择是更改 Joomla 配置。 -
您尝试过更改 joomla 配置文件中的 $live_site 参数吗?
-
OP,您会这么好心地查看答案并奖励赏金吗?如果您不执行任何操作,至少有一半的赏金将被浪费。谢谢。附言如果您决定采用推荐人路线,并且对 nginx.conf 有任何问题,请告诉我。
标签: php nginx docker joomla reverse-proxy