我正在尝试为this项目创建一个基于alpine-fpm的包但是我不能让基于alpine_mysql的图像通过nginx运行,无论我怎么努力。我得到的问题是mooodle安装会进行重定向循环,因此浏览器不会为moodle服务。
nginx配置在this文件中,而我也尝试了这个选项但没有成功(还没有提交更改):
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;
gzip on;
gzip_disable "msie6";
client_max_body_size 10000M;
server {
listen 80 default_server;
server_name _;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_read_timeout 600;
fastcgi_intercept_errors on;
fastcgi_pass moodle_mysql_alpine:9000;
}
}
}
我的docker-compose也是this文件,你可以专注于这些行:
#Basic alpine fpm image
alpine_fpm_base:
build:
context: .
dockerfile: dockerfiles/fpm_alpine/Dockerfile_base
image: ellakcy/moodle:alpine_fpm_base
moodle_mysql_alpine_db:
image: mysql
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "${MOODLE_DB_NAME}"
MYSQL_USER: '${MOODLE_MYSQL_USER}'
MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'
# Mysql Enabled image
nginx:
image: nginx:alpine
ports:
- "7070:80"
volumes:
- './conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro'
links:
- 'moodle_mysql_alpine'
volumes_from:
- 'moodle_mysql_alpine'
moodle_mysql_alpine:
build:
context: .
dockerfile: dockerfiles/fpm_alpine/Dockerfile_mysql
image: ellakcy/moodle:mysql_maria_fpm_alpine
links:
- "moodle_mysql_alpine_db:moodle_db"
- "alpine_fpm_base"
environment:
MOODLE_DB_HOST: "moodle_mysql_alpine_db"
MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
MOODLE_ADMIN: "${MOODLE_ADMIN}"
MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
MOODLE_URL: "http://0.0.0.0:7070"
我尝试通过docker-compose rm && docker-compose up moodle_mysql_alpine_db moodle_mysql_alpine nginx
命令运行它。对nginx日志问题的进一步调查显示,由于某种原因,nginx抛出303重定向:
172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:58 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
172.25.0.1 - - [30/Sep/2017:21:02:58 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
你们的伙伴们知道为什么会这样吗?
我尝试遵循基于https://moopi.uk/mod/page/view.php?id=78的nginx配置,结果如下:
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;
gzip on;
gzip_disable "msie6";
client_max_body_size 10000M;
server {
listen 80 default_server;
server_name _;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_read_timeout 600;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
fastcgi_pass moodle_mysql_alpine:9000;
}
}
}
我仍然得到重定向循环。
根据命令curl -iv http://0.0.0.0:7070
的要求,我收到以下回复:
* Rebuilt URL to: http://0.0.0.0:7070/
* Trying 0.0.0.0...
* Connected to 0.0.0.0 (127.0.0.1) port 7070 (#0)
> GET / HTTP/1.1
> Host: 0.0.0.0:7070
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 303 See Other
HTTP/1.1 303 See Other
< Server: nginx/1.13.3
Server: nginx/1.13.3
< Date: Sun, 01 Oct 2017 09:41:21 GMT
Date: Sun, 01 Oct 2017 09:41:21 GMT
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Connection: keep-alive
Connection: keep-alive
< X-Powered-By: PHP/7.0.23
X-Powered-By: PHP/7.0.23
< Location: http://0.0.0.0:7070
Location: http://0.0.0.0:7070
< Content-Language: en
Content-Language: en
<
<!DOCTYPE html>
<html lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Redirect</title>
* Connection #0 to host 0.0.0.0 left intact
</head><body><div style="margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;">This page should automatically redirect. If nothing is happening please use the continue link below.<br /><a href="http://0.0.0.0:7070">Continue</a></div></body></html>
我尝试使用基于https://docs.moodle.org/29/en/Nginx的配置并产生了这个nginx配置:
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;
gzip on;
gzip_disable "msie6";
client_max_body_size 10000M;
server {
listen 80 default_server;
server_name _;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass moodle_mysql_alpine:9000;
}
location /dataroot/ {
internal;
alias /var/moodledata; # ensure the path ends with /
}
}
}
但我仍然得到303重定向循环。
答案 0 :(得分:0)
最后在nginx中有以下配置:
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;
gzip on;
gzip_disable "msie6";
client_max_body_size 10000M;
server {
listen 7070;
server_name _;
proxy_redirect off;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass moodle_alpine_fpm_mysql:9000;
}
location /dataroot/ {
internal;
alias /var/moodledata/; # ensure the path ends with /
}
}
}
出于某种原因调试了moodle的源代码之后,为了soem的原因,它获得了nginx的监听端口,我设置为moodle的配置(http://0.0.0.0:7070
)的url无效。
答案 1 :(得分:0)
对于我来说,答案是在config.php中设置以下选项
$CFG->wwwroot = 'https://my-site';
$CFG->sslproxy = true;
'sslproxy'选项意味着代理或负载平衡器将处理ssl,从而防止无休止的303重定向(ERR_TOO_MANY_REDIRECTS)。