尝试使用nginx和php5设置docker。这是我的Dockerfile

FROM nginx:1.9.9

RUN apt-get update
RUN apt-get -y install php5-fpm php5-mysql php-apc php5-imagick\
        php5-imap php5-mcrypt php5-curl php5-cli php5-gd php5-pgsql\
        php5-common php-pear curl php5-json

ADD index.html /usr/share/nginx/html/index.html
ADD index.php /usr/share/nginx/html/index.php
ADD default /etc/nginx/sites-available/default

RUN /etc/init.d/php5-fpm restart

我可以使用以下命令来构建它:
sudo docker build -t myuser/nginx-php5:0.1 .

然后按如下方式启动它:
sudo docker run -d -P myuser/nginx-php5:0.1

nginx守护进程正在运行,我确实可以看到我的index.html,但是index.php被“下载”而不是被提供。这表明PHP设置不正确...

我的默认文件:
server {
listen  80;

root /var/www;
index index.php index.html;

server_name localhost;

access_log /var/log/nginx/localhost.com-access.log;
error_log  /var/log/nginx/localhost.com-error.log error;

charset utf-8;

location / {
    try_files $uri $uri/ /index.html /index.php?$query_string;
}

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt  { access_log off; log_not_found off; }

error_page 404 /index.php;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    include fastcgi.conf;
    fastcgi_param HTTPS off;
}

location ~ /\.ht {
    deny all;
}

}

有什么想法我做错了吗?我想问题是我没有做适当的事情来保持php5-fpm运行..而是如何解决此问题?

最佳答案

我认为php-fpm没有运行,因此nginx只是返回php文件,而不是传递给php-fpm进行处理。
您应该创建一个“entrypoint.sh”文件以在运行容器时启动nginx和php-fpm。此外,您必须为php-fpm worker进程正确设置用户和组。

关于php - 使用Nginx和php5设置docker,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35002810/

10-14 16:12
查看更多