gpt4 book ai didi

laravel - Laradock(docker)不断抛出http错误500

转载 作者:行者123 更新时间:2023-12-02 17:00:20 27 4
gpt4 key购买 nike

无论我尝试什么,当我访问我的 docker-machine IP 时,我都会收到 HTTP 错误代码 500。

我通过 Docker 工具箱运行 laradock(操作系统:Windows 10)并运行默认虚拟机。我已经按照视频中的说明设置了 laradock。

我已成功将所需的文件夹安装到虚拟机中,并根据虚拟机中代码的位置更改了 docker-compose.yml:

这是我的 docker-compose.yml 文件:

version: '2'

services:

Nginx Server Container

nginx:
build: ./nginx
volumes_from:
- volumes_source
volumes:
- ./logs/nginx/:/var/log/nginx
ports:
- "80:80"
- "443:443"
links:
- php-fpm

PHP-FPM Container

php-fpm:
build:
context: ./php-fpm
dockerfile: Dockerfile-70
volumes_from:
- volumes_source
expose:
- "9000"
links:
- workspace

MySQL Container

mysql:
build: ./mysql
volumes_from:
- volumes_data
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: root

PostgreSQL Container

postgres:
build: ./postgres
volumes_from:
- volumes_data
ports:
- "5432:5432"
environment:
POSTGRES_DB: homestead
POSTGRES_USER: homestead
POSTGRES_PASSWORD: secret

MariaDB Container

mariadb:
build: ./mariadb
volumes_from:
- volumes_data
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: root

Neo4j Container

neo4j:
build: ./neo4j
ports:
- "7474:7474"
- "1337:1337"
environment:
- NEO4J_AUTH=homestead:secret
volumes_from:
- volumes_data

MongoDB Container

mongo:
build: ./mongo
ports:
- "27017:27017"
volumes_from:
- volumes_data

Redis Container

redis:
build: ./redis
volumes_from:
- volumes_data
ports:
- "6379:6379"

Memcached Container

memcached:
build: ./memcached
volumes_from:
- volumes_data
ports:
- "11211:11211"
links:
- php-fpm

Beanstalkd Container

beanstalkd:
build: ./beanstalkd
ports:
- "11300:11300"
privileged: true
links:
- php-fpm

Beanstalkd Console Container

beanstalkd-console:
build: ./beanstalkd-console
ports:
- "2080:2080"
links:
- beanstalkd

Workspace Utilities Container

workspace:
build:
context: ./workspace
args:
- INSTALL_PRESTISSIMO=false
volumes_from:
- volumes_source
tty: true

Laravel Application Code Container

volumes_source:
build: ./volumes/application
volumes:
- /c/Users/pomodoro.xyz/code:/var/www/laravel

Databases Data Container

volumes_data:
build: ./volumes/data
volumes:
- /var/lib/mysql:/var/lib/mysql
- /var/lib/postgres:/var/lib/postgres
- /var/lib/mariadb:/var/lib/mariadb
- /var/lib/memcached:/var/lib/memcached
- /var/lib/redis:/data
- /var/lib/neo4j:/var/lib/neo4j/data
- /var/lib/mongo:/data/db

Add more Containers below

当我登录工作区并更改文件时,它们会反射(reflect)到主机中,因此我在这方面很擅长。

这是我的工作容器中的文件夹结构(正如视频所示):

root@d463d55e545b:/var/www/laravel# ls -l
total 30
drwxrwxrwx 1 1000 staff 4096 Jul 20 19:58 app
-rwxrwxrwx 1 1000 staff 1646 Jul 20 19:58 artisan
drwxrwxrwx 1 1000 staff 0 Jul 20 19:58 bootstrap
-rwxrwxrwx 1 1000 staff 1272 Jul 20 19:58 composer.json
drwxrwxrwx 1 1000 staff 4096 Jul 20 19:58 config
drwxrwxrwx 1 1000 staff 4096 Jul 20 19:58 database
-rwxrwxrwx 1 1000 staff 503 Jul 20 19:58 gulpfile.js
-rwxrwxrwx 1 1000 staff 12 Jul 21 15:13 index.html
drwxrwxrwx 1 1000 staff 4096 Jul 23 09:24 laradock
-rwxrwxrwx 1 1000 staff 212 Jul 20 19:58 package.json
-rwxrwxrwx 1 1000 staff 1026 Jul 20 19:58 phpunit.xml
drwxrwxrwx 1 1000 staff 4096 Jul 23 10:39 public
-rwxrwxrwx 1 1000 staff 1918 Jul 20 19:58 readme.md
drwxrwxrwx 1 1000 staff 0 Jul 20 19:58 resources
-rwxrwxrwx 1 1000 staff 567 Jul 20 19:58 server.php
drwxrwxrwx 1 1000 staff 0 Jul 20 19:58 storage
drwxrwxrwx 1 1000 staff 0 Jul 20 19:58 tests
drwxrwxrwx 1 1000 staff 0 Jul 20 19:59 vendor

所有 nginx.conf 文件等都被加载到容器中,正如我从 docker exec -it 看到的到我的 nginx 容器中一样。

作为引用,这是我的 laravel.conf

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on;

root /var/www/laravel/public;
index index.php index.html index.htm;

server_name laravel.dev www.laravel.dev;

location / {
try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}

}

和 nginx.conf:

user www-data; worker_processes 4; pid /run/nginx.pid;

events { worker_connections 2048; multi_accept on; use epoll; }

http { server_tokens off; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 15; types_hash_max_size 2048; client_max_body_size 20M; include /etc/nginx/mime.types; default_type application/octet-stream; access_log on; error_log on; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/.conf; include /etc/nginx/sites-available/; open_file_cache max=100; }

daemon off;

这是我的 laravel 根目录的 .env 文件:

APP_ENV=local APP_DEBUG=true APP_KEY=SomeRandomString APP_URL=http://localhost

DB_CONNECTION=mysql DB_HOST=192.168.99.100 DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret

CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync

REDIS_HOST=192.168.99.100 REDIS_PASSWORD=null REDIS_PORT=6379

MAIL_DRIVER=smtp MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null

我还通过登录工作区容器并键入以下内容来设置文件夹的权限:

chmod -R 777 storage bootstrap/cache

但我仍然在 docker-machine ip 上收到 http 500 错误。我错过了什么?

最佳答案

我发现的一个潜在问题是您在 .env 中使用服务主机(DB_HOST、REDIS_HOST)的 IP 地址。这些 IP 地址可能会更改,因此使用容器名称作为主机地址更安全。在您的情况下,您需要使用“DB_HOST=mysql”和“REDIS_HOST=redis”。

http 500 意味着您的 nginx 配置可能没有任何问题,听起来更像是 Laravel 配置问题。我建议您检查 Laravel 日志文件 (storage/logs/laravel.log) 以获取更多信息。

关于laravel - Laradock(docker)不断抛出http错误500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38541831/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com