docker-compose 启动后 laravel使用passport报cURL error 7 报错
docker-compose 文件内容
version: '3'
services:
nginx:
build: ./nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ${APP_CODE_PATH}:${APP_CODE_PATH_CONTAINER}
- ${APP_NGINX_PATH}/logs:/var/log/nginx
- ${APP_NGINX_PATH}/nginx.conf:/etc/nginx/nginx.conf:ro
- ${APP_NGINX_PATH}/conf.d/:/etc/nginx/conf.d/
- ${APP_BASE_PATH}/ssl:/ssl/:rw
- /etc/localtime:/etc/localtime:ro
depends_on:
- mysql
networks:
- code-network
php:
build: ./php-fpm
restart: always
volumes:
- ${APP_CODE_PATH}:${APP_CODE_PATH_CONTAINER}
- ${APP_PHP_PATH}/logs:/var/log/php
- ${APP_PHP_PATH}/php.ini:/usr/local/etc/php/php.ini:ro
- /etc/localtime:/etc/localtime:ro
working_dir: ${APP_CODE_PATH_CONTAINER}/Project-carsafe-201805
depends_on:
- mysql
networks:
- code-network
mysql:
build: ./mysql
restart: always
ports:
- "3306:3306"
volumes:
- ${APP_MYSQL_PATH}/data/:/var/lib/mysql
- ${APP_MYSQL_PATH}/logs:/var/log/mysql
- ${APP_MYSQL_PATH}/my.cnf:/etc/mysql/my.cnf
- ${APP_MYSQL_PATH}/conf.d/:/etc/mysql/conf.d
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_ROOT_PASSWORD=root
networks:
- code-network
redis:
build: ./redis
restart: always
ports:
- "6379:6379"
volumes:
- ${APP_REDIS_PATH}/data/:/data/
- ${APP_REDIS_PATH}/logs:/var/log/redis
- /etc/localtime:/etc/localtime:ro
environment:
- ALLOW_EMPTY_PASSWORD=yes
entrypoint: redis-server --appendonly yes
networks:
- code-network
networks:
code-network:
driver: bridge
nginx.conf 内容
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
nginx/conf.d 内容
server {
listen 80;
server_name test.carsafe.com;
root /usr/share/nginx/html/Project-carsafe-201805/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
实例:
$data = [
"username" => "18622221320",
"password" => "1234",
"scope" => "",
"client_id" => "2",
"client_secret" => "BHMgjY1YApfhG9sHSY4fgdIZjR0jYDVaWH2vkAoe",
"grant_type" => "password"
];
//http://172.19.0.5/
$response = $client->post(url('oauth/token'), [
'form_params' => $data,
]);
报错:
cURL error 7: Failed to connect to test.carsafe.com port 80: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
但在上面 url改为 docker中php 的 容器IP地址 就没问题