du3669
2017-09-30 18:14
浏览 493
已采纳

Docker nginx&fpm:我的nginx错误404

I try to run a php application with fpm for this project. And I am trying to make the nginx image to run the fpm based solution. My docker-compose.yml is:

version: '2'
services:

# apache based images

  # A base image for apache - based moodle builds
  moodle_apache_base:
      build:
        context: .
        dockerfile: dockerfiles/apache/Dockerfile_base
      image: ellakcy/moodle:apache_base

  # Mysql running variant
  moodle_mysql_db:
    image: mysql
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_ONETIME_PASSWORD: "yes"
      MYSQL_DATABASE: "${MOODLE_DB_NAME}"
      MYSQL_USER: '${MOODLE_MYSQL_USER}'
      MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'

  moodle_mysql:
    build:
      context: .
      dockerfile: dockerfiles/apache/Dockerfile_mysql
    image: ellakcy/moodle:mysql_maria_apache
    links:
      - "moodle_mysql_db:moodle_db"
      - "moodle_apache_base"
    ports:
      - "6080:80"
    environment:
      MOODLE_DB_HOST: "moodle_mysql_db"
      MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
      MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
      MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
      MOODLE_ADMIN: "${MOODLE_ADMIN}"
      MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
      MOODLE_URL: "http://0.0.0.0:6080"

  # postgresql running variant
  moodle_psql_db:
    image: postgres
    environment:
      POSTGRES_DB: "${MOODLE_DB_NAME}"
      POSTGRES_USER: '${MOODLE_MYSQL_USER}'
      POSTGRES_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'

  moodle_psql:
    build:
      context: .
      dockerfile: dockerfiles/apache/Dockerfile_postgrtesql
    image: ellakcy/moodle:postgresql_apache
    links:
      - "moodle_psql_db:moodle_db"
      - "moodle_apache_base"
    ports:
      - "6082:80"
    environment:
      MOODLE_DB_HOST: "moodle_psql_db"
      MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
      MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
      MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
      MOODLE_ADMIN: "${MOODLE_ADMIN}"
      MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
      MOODLE_URL: "http://0.0.0.0:6082"

  # Testing mariadb support
  moodle_maria_db:
      image: mariadb
      environment:
        MYSQL_RANDOM_ROOT_PASSWORD: "yes"
        MYSQL_ONETIME_PASSWORD: "yes"
        MYSQL_DATABASE: "${MOODLE_DB_NAME}"
        MYSQL_USER: '${MOODLE_MYSQL_USER}'
        MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'

  moodle_maria:
      image: ellakcy/moodle:mysql_maria_apache
      links:
        - "moodle_mysql"
        - "moodle_maria_db:moodle_db"
      ports:
        - "6081:80"
      environment:
        MOODLE_DB_HOST: "moodle_maria_db"
        MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
        MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
        MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
        MOODLE_ADMIN: "${MOODLE_ADMIN}"
        MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
        MOODLE_URL: "http://0.0.0.0:6081"

#Alpine fpm based images



  #Basic alpine fpm image
  alpine_fpm_base:
    build:
      context: .
      dockerfile: dockerfiles/fpm_alpine/Dockerfile_base
    image: ellakcy/moodle:alpine_fpm_base

  moodle_mysql_alpine_db:
    image: mysql
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_ONETIME_PASSWORD: "yes"
      MYSQL_DATABASE: "${MOODLE_DB_NAME}"
      MYSQL_USER: '${MOODLE_MYSQL_USER}'
      MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'

  # Mysql Enabled image

  nginx:
   image: nginx:alpine
   ports:
     - "7070:80"
   volumes:
     - './conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro'
   links:
     - 'moodle_mysql_alpine'
   volumes_from:
     - 'moodle_mysql_alpine'

  moodle_mysql_alpine:
    build:
      context: .
      dockerfile: dockerfiles/fpm_alpine/Dockerfile_mysql
    image: ellakcy/moodle:mysql_maria_fpm_alpine
    links:
      - "moodle_mysql_alpine_db:moodle_db"
      - "alpine_fpm_base"
    environment:
      MOODLE_DB_HOST: "moodle_mysql_alpine_db"
      MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
      MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
      MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
      MOODLE_ADMIN: "${MOODLE_ADMIN}"
      MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
      MOODLE_URL: "http://0.0.0.0:7070/moodle_mysql"

And the nginx configuration is:

events {
  worker_connections  768;
}

http {
  include  /etc/nginx/mime.types;
  default_type  application/octet-stream;

  charset  utf-8;

  gzip  on;
  gzip_disable  "msie6";
  client_max_body_size 10000M;

  server {
    listen  80;

    root  /var/www/www;
    index  index.php;

    location / {
      try_files  $uri $uri/ =404;
    }

    location ~ \.php$ {
      fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
      fastcgi_param  SERVER_SOFTWARE    nginx;
      fastcgi_param  QUERY_STRING       $query_string;
      fastcgi_param  REQUEST_METHOD     $request_method;
      fastcgi_param  CONTENT_TYPE       $content_type;
      fastcgi_param  CONTENT_LENGTH     $content_length;
      fastcgi_param  DOCUMENT_ROOT      $document_root;
      fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
      fastcgi_param  REQUEST_URI        $request_uri;
      fastcgi_param  DOCUMENT_URI       $document_uri;
      fastcgi_param  SERVER_PROTOCOL    $server_protocol;
      fastcgi_param  REMOTE_ADDR        $remote_addr;
      fastcgi_param  REMOTE_PORT        $remote_port;
      fastcgi_param  SERVER_ADDR        $server_addr;
      fastcgi_param  SERVER_PORT        $server_port;
      fastcgi_param  SERVER_NAME        $server_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      fastcgi_read_timeout 600;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_intercept_errors  on;
      fastcgi_index index.php;
      fastcgi_pass  moodle_mysql_alpine:9000;
    }
  }
}

But regardless what I've tried to do is useless I cannot make my moodle_mysql_alpine to get served via nginx. Do you fellows have an Idea how I can make it to get served? Also keep in minf that I do not care to keep volumes in my local filesysytem bevcause this file is intended to build and run the images just to upload them to an image repository.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doupo1908 2017-09-30 19:51
    已采纳

    In the end I did wrong on the root folder. It was /var/www/html instead of /var/www/www one. So the nginx correctly prompted me to the 404 page because there was no file/volume mounted to it.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题