我正在做这个wordpress 解决方案并且由于“节食”的原因,我开始转向拍摄高山地区的图像。
在此我设法使用外部配置(文件),然后通过卷将其传递到 nginx。
server {
listen 80;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ .php{
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.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 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 DOCUMENT_ROOT $document_root;
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_intercept_errors on;
}
}
但是当我尝试通过浏览器访问它时http://本地主机:8080(我将端口 80 映射到我的docker-compose.yml):
version: '2'
services:
nginx:
image: nginx:alpine
ports:
- "8080:80"
volumes:
- './conf/nginx/:/etc/nginx/conf.d/:ro'
links:
- "wordpress"
volumes_from:
- "wordpress:ro"
wordpress-db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
wordpress:
build:
context: .
dockerfile: Dockerfile
image: ellakcy/wordpressswithplugins:alpine
links:
- wordpress-db
environment:
WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
WORDPRESS_URL: '${WORDPRESS_URL}'
但由于某种原因,似乎重定向到端口 80。
此外,当我通过命令运行时,docker-compose up
我收到以下日志:
wordpress_1 | 172.23.0.4 - 18/Aug/2017:12:36:57 +0000 "GET /index.php" 301
nginx_1 | 172.23.0.1 - - [18/Aug/2017:12:36:57 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
wordpress_1 | 172.23.0.4 - 18/Aug/2017:12:41:22 +0000 "GET /index.php" 301
nginx_1 | 172.23.0.1 - - [18/Aug/2017:12:41:22 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
所以我猜测由于某种原因,nginx 执行了 301 重定向到端口 80。你知道为什么会发生这种情况吗?
编辑1
我也尝试将 8080 端口设置到 nginx 配置中:
Nginx 配置:
server {
listen 8080;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ .php{
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.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 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 DOCUMENT_ROOT $document_root;
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_intercept_errors on;
}
}
docker-compose.yml:
版本:'2' 服务:nginx: 图像:nginx:alpine 端口: - “8080:8080” 卷: - './conf/nginx/:/etc/nginx/conf.d/:ro' 链接: - “wordpress” volumes_from: - “wordpress:ro”
wordpress-db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
wordpress:
build:
context: .
dockerfile: Dockerfile
image: ellakcy/wordpressswithplugins:alpine
links:
- wordpress-db
environment:
WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
WORDPRESS_URL: '${WORDPRESS_URL}'
我仍然有同样的行为
我正在做这个wordpress 解决方案并且由于“节食”的原因,我开始转向拍摄高山地区的图像。
在此我设法使用外部配置(文件),然后通过卷将其传递到 nginx。
server {
listen 80;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ .php{
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.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 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 DOCUMENT_ROOT $document_root;
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_intercept_errors on;
}
}
但是当我尝试通过浏览器访问它时http://本地主机:8080(我将端口 80 映射到我的docker-compose.yml):
version: '2'
services:
nginx:
image: nginx:alpine
ports:
- "8080:80"
volumes:
- './conf/nginx/:/etc/nginx/conf.d/:ro'
links:
- "wordpress"
volumes_from:
- "wordpress:ro"
wordpress-db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
wordpress:
build:
context: .
dockerfile: Dockerfile
image: ellakcy/wordpressswithplugins:alpine
links:
- wordpress-db
environment:
WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
WORDPRESS_URL: '${WORDPRESS_URL}'
但由于某种原因,似乎重定向到端口 80。
此外,当我通过命令运行时,docker-compose up
我收到以下日志:
wordpress_1 | 172.23.0.4 - 18/Aug/2017:12:36:57 +0000 "GET /index.php" 301
nginx_1 | 172.23.0.1 - - [18/Aug/2017:12:36:57 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
wordpress_1 | 172.23.0.4 - 18/Aug/2017:12:41:22 +0000 "GET /index.php" 301
nginx_1 | 172.23.0.1 - - [18/Aug/2017:12:41:22 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
所以我猜测由于某种原因,nginx 执行了 301 重定向到端口 80。你知道为什么会发生这种情况吗?
编辑1
我也尝试将 8080 端口设置到 nginx 配置中:
Nginx 配置:
server {
listen 8080;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ .php{
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.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 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 DOCUMENT_ROOT $document_root;
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_intercept_errors on;
}
}
docker-compose.yml:
version: '2'
services:
nginx:
image: nginx:alpine
ports:
- "8080:8080"
volumes:
- './conf/nginx/:/etc/nginx/conf.d/:ro'
links:
- "wordpress"
volumes_from:
- "wordpress:ro"
wordpress-db:
image: mariadb
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_ONETIME_PASSWORD: "yes"
MYSQL_DATABASE: "wordpress"
MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
wordpress:
build:
context: .
dockerfile: Dockerfile
image: ellakcy/wordpressswithplugins:alpine
links:
- wordpress-db
environment:
WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
WORDPRESS_URL: '${WORDPRESS_URL}'
我仍然遇到同样的行为。
编辑2
我还尝试使用以下 nginx 设置(针对 nginx 容器)
server {
listen 8080;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ .php {
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.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 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 DOCUMENT_ROOT $document_root;
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_intercept_errors on;
}
}
但我依然看不到前进道路上的光明。