Magento2 docker env,mysql端口方向错误

时间:2019-06-01 12:23:08

标签: mysql docker nginx magento2

我正在docker中的magento 2项目的本地Web开发环境中工作。

这些是我的重要端口:

  • NGINX_PORT = 8000
  • NGINX_SEC_PORT = 3000
  • PHPMYADMIN_PORT = 8080
  • MYSQL_PORT = 8989

一切正常,可以使用mysql,通过phpmyadmin访问mysql,并通过预安装的apache路径访问项目。

http://localhost/{path_to_project}/magento2/index.php

现在的问题是我通过端口访问的apache路径和nginx路径之间存在差异:

http://localhost:8000/

在两者中,我都在index.php中添加了pdo检查:

try {
    $dsn = 'mysql:host=mysql;dbname=Customer;charset=utf8;port=8989';
    $pdo = new PDO($dsn, 'user', 'password');
} catch (PDOException $e) {
    echo $e->getMessage();
}

因此,如果我通过apache http://localhost/ {path_to_project} /magento2/index.php,它表明与mysql的连接有效。

但是当我通过nginx http://localhost:8000/时,它表明该连接被拒绝,原因是无法访问端口3306,但它应该使用端口8989,如上所述。

我认为Nginx配置可能有问题,但是没有错误日志或其他可以用来解决此问题的东西。

文件:

Nginx配置:

upstream fastcgi_backend {
    server  php:9000;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name localhost;
    set $MAGE_ROOT /var/www/html;
    include /var/www/html/nginx.conf.sample;

    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    #root /var/www/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Docker-compose.yml:

version: '3'
services:
  app:
    image: nginx:alpine
    volumes:
      - "./docker/etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
      - "./docker/etc/ssl:/etc/ssl"
      - "${NGINX_APP_PATH}:/var/www/html"
      - "./docker/etc/nginx/default.template.conf:/etc/nginx/conf.d/default.template"
    ports:
      - "${NGINX_PORT}:80"
      - "${NGINX_SEC_PORT}:443"
    environment:
      - NGINX_HOST=${NGINX_HOST}
    command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
    depends_on:
      - php
      - mysqldb
  php:
    image: nanoninja/php-fpm:${PHP_VERSION}
    volumes:
      - "./docker/etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
      - "${NGINX_APP_PATH}:/var/www/html"
  myadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - "${PHPMYADMIN_PORT}:80"
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=${MYSQL_HOST}
    depends_on:
      - mysqldb
  mysqldb:
    image: mysql:${MYSQL_VERSION}
    env_file:
      - ".env"
    environment:
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    ports:
      - "${MYSQL_PORT}:3306"
    volumes:
      - "./docker/data/db/mysql:/var/lib/mysql"

  mailhog:
    container_name: mailhog
    image: mailhog/mailhog
    ports:
      - 1025:1025
      - 8025:8025

因此,如果您有任何想法或建议,请与我联系。

谢谢

0 个答案:

没有答案