加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 21:31:46 所属栏目:Nginx 来源:网络整理
导读:我正在使用Docker图像配置设置一个带有Docker的Laravel应用程序,我在这里找到:https://blog.pusher.com/docker-for-development-laravel-php/ 现在,这在我的Ubuntu机器(16.04)上工作正常,但在Window(10 Pro)上我得到一个奇怪的错误.它首先抱怨没有找到compo

我正在使用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 

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目录的完整路径.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读