php – Nginx在Windows上指向Docker的错误目录

前端之家收集整理的这篇文章主要介绍了php – Nginx在Windows上指向Docker的错误目录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用Docker图像配置设置一个带有Docker的Laravel应用程序,我在这里找到:https://blog.pusher.com/docker-for-development-laravel-php/

现在,这在我的Ubuntu机器(16.04)上工作正常,但在Window(10 Pro)上我得到一个奇怪的错误.它首先抱怨没有找到composer.json文件.然后,随着我对localhost:8000的每个请求,我收到以下错误

15#15: *1 open() "/var/www/public404" Failed (2: No such file or directory),client: 172.17.0.1,server:,request: "GET / HTTP/1.1",host: "localhost:8000"

我对此很新,但似乎Nginx指向/ var / www / public404 – 我不知道“404”是如何到达那里的.我有一种感觉,它与行try_files $uri = 404有关;但是,在site.conf文件中,我真的不知道它是如何工作的,我不想破坏它…奇怪的是,这适用于Ubuntu,但不适用于Windows(或者可能不是很奇怪)在所有?).

我使用docker build. -t my-image用于构建映像和docker运行-p 8000:80 –name =“my-container”my-image以使用映像运行容器.

所有配置文件的EOL都设置为换行符.有谁知道我怎么解决这个问题?

Dockerfile

FROM Nginx:mainline-alpine
LABEL maintainer="John Doe Nginx.conf /etc/Nginx/Nginx.conf
COPY supervisord.conf /etc/supervisord.conf
COPY site.conf /etc/Nginx/sites-available/default.conf

RUN apk add --update \
PHP7 \
PHP7-fpm \
PHP7-pdo \
PHP7-pdo_MysqL \
PHP7-mcrypt \
PHP7-mbstring \
PHP7-xml \
PHP7-openssl \
PHP7-json \
PHP7-phar \
PHP7-zip \
PHP7-dom \
PHP7-session \
PHP7-tokenizer \
PHP7-zlib && \
PHP7 -r "copy('http://getcomposer.org/installer','composer-setup.PHP');" && \
PHP7 composer-setup.PHP --install-dir=/usr/bin --filename=composer && \
PHP7 -r "unlink('composer-setup.PHP');" && \
ln -s /etc/PHP7/PHP.ini /etc/PHP7/conf.d/PHP.ini

RUN apk add --update \
bash \
openssh-client \
supervisor

RUN mkdir -p /etc/Nginx && \
mkdir -p /etc/Nginx/sites-available && \
mkdir -p /etc/Nginx/sites-enabled && \
mkdir -p /run/Nginx && \
ln -s /etc/Nginx/sites-available/default.conf /etc/Nginx/sites-enabled/default.conf && \
mkdir -p /var/log/supervisor && \
rm -Rf /var/www/* && \
chmod 755 /start.sh

RUN sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" \
-e "s/variables_order = \"GPCS\"/variables_order = \"EGPCS\"/g" \
/etc/PHP7/PHP.ini && \
sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" \
-e "s/;catch_workers_output\s*=\s*yes/catch_workers_output = yes/g" \
-e "s/user = nobody/user = Nginx/g" \
-e "s/group = nobody/group = Nginx/g" \
-e "s/;listen.mode = 0660/listen.mode = 0666/g" \
-e "s/;listen.owner = nobody/listen.owner = Nginx/g" \
-e "s/;listen.group = nobody/listen.group = Nginx/g" \
-e "s/listen = 127.0.0.1:9000/listen = \/var\/run\/PHP-fpm.sock/g" \
-e "s/^;clear_env = no$/clear_env = no/" \
/etc/PHP7/PHP-fpm.d/www.conf

EXPOSE 443 80
WORKDIR /var/www

CMD ["/start.sh"]

start.sh

#!/bin/bash

# ----------------------------------------------------------------------
# Create the .env file if it does not exist.
# ----------------------------------------------------------------------

if [[ ! -f "/var/www/.env" ]] && [[ -f "/var/www/.env.example" ]];
then
cp /var/www/.env.example /var/www/.env
fi

# ----------------------------------------------------------------------
# Run Composer
# ----------------------------------------------------------------------

if [[ ! -d "/var/www/vendor" ]];
then
cd /var/www
composer update
composer dump-autoload -o
fi

# ----------------------------------------------------------------------
# Start supervisord
# ----------------------------------------------------------------------

exec /usr/bin/supervisord -n -c /etc/supervisord.conf

site.conf

server {
listen 80;

root /var/www/public;
index index.PHP index.html;

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

location ~ /\. {
deny all;
}

location ~ \.PHP${
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass unix:/var/run/PHP-fpm.sock;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

Nginx.conf

user Nginx;
worker_processes 1;

error_log /var/log/Nginx/error.log warn;
pid /var/run/Nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/Nginx/mime.types;
default_type application/octet-stream;
access_log off;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/Nginx/sites-enabled/*.conf;
}

supervisord.conf

[unix_http_server]
file=/dev/shm/supervisor.sock

[supervisord]
logfile=/tmp/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=warn
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=root

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///dev/shm/supervisor.sock

[program:PHP-fpm7]
command = /usr/sbin/PHP-fpm7 --nodaemonize --fpm-config /etc/PHP7/PHP-fpm.d/www.conf
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:Nginx]
command=/usr/sbin/Nginx -g "daemon off;"
autostart=true
autorestart=true
priority=10
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
最佳答案
正如上面的评论中提到的,我只是忘了在docker run命令中添加-v参数,如下所示:

docker run -p 8000:80 -v $PWD/src:/var/www --name="my-container" my-image

… $PWD / src是src目录的完整路径.

原文链接:https://www.f2er.com/nginx/434455.html

猜你在找的Nginx相关文章