我最近開始嘗試對我的服務進行 Dockerize 化,并且我已經到了 Dockerize 已經構建了映像的所有內容的地步。現在我正在嘗試為還沒有的 facileManager (FM) 構建一個影像。我已經讓它大部分作業了,但是在 Nginx 后面運行它時遇到了問題。FM 通常是一個 apache-php 應用程式,不包含 Nginx 的安裝說明。我注意到我的容器/影像是,當我通過已發布的埠直接連接到它時它作業正常,但是如果我嘗試通過 Nginx 連接到它,它會出錯,抱怨 .htaccess 檔案不起作用。我不是 Apache 或 Nginx 方面的專家,所以我進行了 Google 搜索,但除了 Wordpress 之外沒有想出太多關于它的“漂亮網址”的類似問題,所以我
首先是應用程式的 Github 存盤庫:https ://github.com/WillyXJ/facileManager/tree/ea159f5f6112727de8422c552aa05b6682aa4d79/server
.htaccess 檔案具體是:
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|txt)$">
Header set Cache-Control "max-age=7200"
</FilesMatch>
<FilesMatch "\.(jpe?g|png|gif|ico)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
我得到的確切錯誤來自這里: https ://github.com/WillyXJ/facileManager/blob/ea159f5f6112727de8422c552aa05b6682aa4d79/server/fm-includes/init.php#L153
if (!defined('INSTALL')) {
if (@dns_get_record($_SERVER['SERVER_NAME'], DNS_A DNS_AAAA)) {
$test_output = getPostData($GLOBALS['FM_URL'] . 'admin-accounts.php?verify', array('module_type' => 'CLIENT'));
$test_output = isSerialized($test_output) ? unserialize($test_output) : $test_output;
if (strpos($test_output, 'Account is not found.') === false) {
$message = sprintf(_('The required .htaccess file appears to not work with your Apache configuration which is required by %1s. '
. 'AllowOverride None in your configuration may be blocking the use of .htaccess or %s is not resolvable.'),
$fm_name, $_SERVER['SERVER_NAME']);
if ($single_check) {
bailOut($message);
} else {
$requirement_check .= displayProgress(_('Test Rewrites'), false, 'display', $message);
$error = true;
}
} else {
if (!$single_check) $requirement_check .= displayProgress(_('Test Rewrites'), true, 'display');
}
}
}
Nginx 配置:
server {
listen 80;
server_tokens off;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name bound.example.com;
ssl_certificate /etc/nginx/ssl/live/bound.example.com/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/live/bound.example.com/privkey.pem;
include /etc/nginx/ssl/options-ssl-nginx.conf;
ssl_dhparam /etc/nginx/ssl/ssl-dhparams.pem;
location / {
proxy_pass http://FM.; <<< Docker service name
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
}
}
我的 Dockerfile/命令運行:https ://github.com/MeCJay12/facileManager-docker
FROM php:7.4-apache
ENV TZ=UTC
ENV Version=4.2.0
ARG DEBIAN_FRONTEND=noninteractive
WORKDIR /src
RUN apt-get update \
&& apt-get -qqy install wget libldb-dev libldap2-dev tzdata \
&& wget http://www.facilemanager.com/download/facilemanager-complete-$Version.tar.gz \
&& tar -xvf facilemanager-complete-$Version.tar.gz \
&& mv facileManager/server/* /var/www/html/
RUN ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so \
&& docker-php-ext-install mysqli ldap \
&& a2enmod rewrite dump_io
COPY php.ini /usr/local/etc/php/php.ini
RUN rm -r /src
額外問題:直接通過發布的埠訪問此容器/影像時,影像全部損壞。我認為它是相關的,因為 .htaccess 檔案包含對影像檔案的參考。
在此先感謝您的幫助!
uj5u.com熱心網友回復:
在https://github.com/WillyXJ/facileManager/issues/491找到解決方案。需要洗掉 web 應用程式中運行不正常的檢查。
uj5u.com熱心網友回復:
點數:
- 在您的代理通行證中包含 $request_uri
- 在您的代理位置塊中提供決議器
- 在 Docker 的網路堆疊中為您的容器宣告一個條目
- 在您的服務名稱中使用所有小寫字母
下面是我用來反向代理到 Ubiquiti Unifi 容器的組態檔。我所有的 certbot 都是在場外處理的,所以我不需要在這里考慮。如果您比較我們的位置塊,問題可能會立即顯現出來,但為了清楚起見,我會解釋一下。
您需要查看的是您的代理通行證指令。這當然是魔術代理發生的地方。我注意到您沒有包含 $request_uri,因此 nginx 收到的任何請求bound.example.com/testpage1都會向上游 apache 服務器發送請求bound.example.com。當然,如果您需要包括一個埠,就像我在這里所做的那樣8443,這也是這樣做的地方。
如果您包含此變數,它應該可以解決您的問題。
以下內容沒有回答您的問題,但我想我也會將其包括在內,作為一些有用的資訊。
另外,我只想指出我已經包含了一個決議器。IP 地址 127.0.0.11 指向Docker 的內部 DNS 決議器。您可能不需要包含此內容,但是我自己這樣做是為了確保我沒有遇到奇怪的問題。最后,我只想建議您考慮升級您的 SSL 設定,以確保您免受來自較弱 SSL/TLS 版本的攻擊。
我希望將變數 $request_uri 添加到您的代理通行證指令是使您的站點正常運行所需的全部內容。
server {
listen 80;
server_name unifi.localdomain;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name unifi.localdomain;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload;";
ssl_protocols TLSv1.3 TLSv1.2;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_session_timeout 1d;
ssl_ciphers ALL:!RSA:!CAMELLIA:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SHA1:!SHA256:!SHA384;
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/privkey.pem;
ssl_dhparam /etc/nginx/certs/dhparam.pem;
location / {
resolver 127.0.0.11;
proxy_pass https://unifi:8443$request_uri;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
此外
Further to the above, I have had a chance to test this out in my own environment and was able to get it working, seemingly (although I did not go through the install procedure). I found that there would be no DNS entry in the docker resolver if I did not declare a network address on the docker network stack for this container. I used the following docker configuration;
version: "3.4"
services:
fm:
build: ./boundexample
container_name: "fm"
networks:
primary:
ipv4_address: "172.19.0.11"
nginx:
image: "nginx:stable"
container_name: "nginx"
restart: "unless-stopped"
environment:
TZ: "Australia/Perth"
networks:
primary:
ipv4_address: "172.19.0.2"
ports:
- "10.0.0.4:80:80/tcp"
- "10.0.0.4:443:443/tcp"
networks:
primary:
driver: bridge
driver_opts:
parent: enp3s0.2
ipam:
config:
- subnet: "172.19.0.0/24"
where the directory boundexample pointed to a local copy of your github repository. My nginx configuration was the same as you provided, only I modified for my own SSL and used the following in my location block;
resolver 127.0.0.11;
proxy_pass http://fm$request_uri;
It is also possible that using FM in upper case within your docker configuration may cause you problems, I was unable to use upper case myself as docker-compose would not permit it.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/425292.html
上一篇:DNS_PROBE_FINISHED_NXDOMAIN–在macOS上使用Homebrew設定WordPress開發環境
