我正在使用Dockerising我的webserver / PHP工作流程.
但因为我在Windows上,我需要使用虚拟机.我选择了boot2docker,这是一个在VirtualBox中运行并适用于Docker的Tiny Core Linux.
我选择了三个容器:
> nginx:官方Nginx容器;
> jprjr/php-fpm:一个PHP-fpm容器;
> mysql:用于数据库.
在boot2docker中,/ www /包含我的web项目和conf /,它有以下树:
conf
│
├───fig
│ fig.yml
│
└───Nginx
Nginx.conf
servers-global.conf
servers.conf
因为docker-compose不能用于boot2docker,所以我必须使用fig来自动化所有东西.这是我的fig.xml:
MysqL:
image: MysqL
environment:
- MysqL_ROOT_PASSWORD=root
ports:
- 3306:3306
PHP:
image: jprjr/PHP-fpm
links:
- MysqL:MysqL
volumes:
- /www:/srv/http:ro
ports:
- 9000:9000
Nginx:
image: Nginx
links:
- PHP:PHP
volumes:
- /www:/www:ro
ports:
- 80:80
command: Nginx -c /www/conf/Nginx/Nginx.conf
这是我的Nginx.conf:
daemon off;
user Nginx;
worker_processes 1;
error_log /var/log/Nginx/error.log debug;
pid /var/run/Nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/Nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/Nginx/access.log main;
sendfile off;
keepalive_timeout 65;
index index.PHP index.html index.htm;
include /www/conf/Nginx/servers.conf;
autoindex on;
}
而servers.conf:
server {
server_name lab.dev;
root /www/lab/;
include /www/conf/Nginx/servers-global.conf;
}
# Some other servers (vhosts)
而servers-global.conf:
listen 80;
location ~* \.PHP${
fastcgi_index index.PHP;
fastcgi_pass PHP:9000;
include /etc/Nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /srv/http$fastcgi_script_name;
}
所以现在的问题(抱歉所有配置,我认为需要清楚地解释问题):如果我访问lab.dev,没问题(这表明主机是在Windows中创建的)但是如果我尝试访问实验室.dev / test_autoload /,我找不到文件..我知道这来自PHP-fpm无法访问文件,Nginx日志确认这一点:
Nginx_1 | 2015/05/28 14:56:02 [error] 5#5: *3 FastCGI sent in stderr:
"Primary script unkNown" while reading response header from upstream,
client: 192.168.59.3, server: lab.dev, request: "GET /test_autoload/ HTTP/1.1",
upstream: "fastcgi://172.17.0.120:9000", host: "lab.dev", referrer: "http://lab.dev/"
我知道在两个容器的lab / test_autoload /中都有一个index.PHP,我已经检查过了.在Nginx中,它位于/www/lab/test_autoload/index.PHP和/srv/http/lab/test_autoload/index.PHP中.
我相信问题来自root和/或fastcgi_param SCRIPT_FILENAME,但我不知道如何解决它.
我尝试了很多东西,比如修改根,使用重写规则,添加/删除some / s等,但没有任何改变.
再次,抱歉所有这个配置,但我认为需要描述我所处的环境.
解决方法:
我终于找到了答案.
变量$fastcgi_script_name没有考虑根(逻辑,因为它包含www / otherwise.这意味着全局文件不能工作.例如:
# "generated" vhost
server {
server_name lab.dev;
root /www/lab/;
listen 80;
location ~* \.PHP${
fastcgi_index index.PHP;
fastcgi_pass PHP:9000;
include /etc/Nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /srv/http$fastcgi_script_name;
# I need to add /lab after /srv/http because it requests PHP to look at the root of the web files, not in the lab/ folder
# fastcgi_param SCRIPT_FILENAME /srv/http/lab$fastcgi_script_name;
}
}
这意味着我无法在一个地方编写实验室,我需要在两个不同的地方(root和fastcgi_param)编写,所以我决定自己编写一个使用.json的小PHP脚本并将其转换为服务器.conf文件.如果有人想看看它,请问,分享它会很愉快.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。