Docker nginx: Redireciona para a porta 80 em vez da porta mapeada

1

Estou a fazer esta solução para wordpress e por razões de "dietas" estou a mudar para a alpine imagens baseadas em imagens.

Nisto eu consegui usar uma configuração externa ( file ) e via volume eu passo no nginx.

server {
  listen 80;
  root /var/www/html;
  index index.php;

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

  location ~ .php{
    try_files $uri =404;
    fastcgi_pass wordpress:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    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  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  DOCUMENT_ROOT      $document_root;
    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_intercept_errors  on;
  }
}

Mas quando eu tento visitá-lo em um navegador, dando link (onde mapeio a porta 80 em meu docker-compose.yml ):

version: '2'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "8080:80"
    volumes:
      - './conf/nginx/:/etc/nginx/conf.d/:ro'
    links:
      - "wordpress"
    volumes_from:
      - "wordpress:ro"

  wordpress-db:
    image: mariadb
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_ONETIME_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress"
      MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
      MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'

  wordpress:
    build:
      context: .
      dockerfile: Dockerfile
    image: ellakcy/wordpressswithplugins:alpine
    links:
      - wordpress-db
    environment:
        WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
        WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
        WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
        WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
        WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
        WORDPRESS_URL: '${WORDPRESS_URL}'

Mas, por algum motivo, parece que redireciona para a porta 80.

Além disso, quando executo o comando docker-compose up , recebo a seguinte parte do log:

wordpress_1     | 172.23.0.4 -  18/Aug/2017:12:36:57 +0000 "GET /index.php" 301
nginx_1         | 172.23.0.1 - - [18/Aug/2017:12:36:57 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
wordpress_1     | 172.23.0.4 -  18/Aug/2017:12:41:22 +0000 "GET /index.php" 301
nginx_1         | 172.23.0.1 - - [18/Aug/2017:12:41:22 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"

Então eu acho que, por algum motivo, o nginx faz um redirecionamento 301 para a porta 80. Você tem alguma ideia de por que isso acontece?

Editar 1

Eu também tentei configurar a porta 8080 na configuração nginx também:

Configuração do Nginx:

server {
  listen 8080;
  root /var/www/html;
  index index.php;

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

  location ~ .php{
    try_files $uri =404;
    fastcgi_pass wordpress:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    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  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  DOCUMENT_ROOT      $document_root;
    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_intercept_errors  on;
  }
}

docker-compose.yml:

versão: '2'     Serviços:       nginx:         imagem: nginx: alpino         portos:           - "8080: 8080"         volumes:           - './conf/nginx/:/etc/nginx/conf.d/:ro'         links:           - "wordpress"         volumes_from:           - "wordpress: ro"

  wordpress-db:
    image: mariadb
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_ONETIME_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress"
      MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
      MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'

  wordpress:
    build:
      context: .
      dockerfile: Dockerfile
    image: ellakcy/wordpressswithplugins:alpine
    links:
      - wordpress-db
    environment:
        WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
        WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
        WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
        WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
        WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
        WORDPRESS_URL: '${WORDPRESS_URL}'

Eu ainda tenho o mesmo comportamento

Estou a fazer esta solução para wordpress e por razões de "dietas" estou a mudar para a alpine imagens baseadas em imagens.

Nisto eu consegui usar uma configuração externa ( file ) e via volume eu passo no nginx.

server {
  listen 80;
  root /var/www/html;
  index index.php;

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

  location ~ .php{
    try_files $uri =404;
    fastcgi_pass wordpress:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    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  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  DOCUMENT_ROOT      $document_root;
    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_intercept_errors  on;
  }
}

Mas quando eu tento visitá-lo em um navegador, dando link (onde mapeio a porta 80 em meu docker-compose.yml ):

version: '2'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "8080:80"
    volumes:
      - './conf/nginx/:/etc/nginx/conf.d/:ro'
    links:
      - "wordpress"
    volumes_from:
      - "wordpress:ro"

  wordpress-db:
    image: mariadb
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_ONETIME_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress"
      MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
      MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'

  wordpress:
    build:
      context: .
      dockerfile: Dockerfile
    image: ellakcy/wordpressswithplugins:alpine
    links:
      - wordpress-db
    environment:
        WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
        WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
        WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
        WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
        WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
        WORDPRESS_URL: '${WORDPRESS_URL}'

Mas, por algum motivo, parece que redireciona para a porta 80.

Além disso, quando executo o comando docker-compose up , recebo a seguinte parte do log:

wordpress_1     | 172.23.0.4 -  18/Aug/2017:12:36:57 +0000 "GET /index.php" 301
nginx_1         | 172.23.0.1 - - [18/Aug/2017:12:36:57 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"
wordpress_1     | 172.23.0.4 -  18/Aug/2017:12:41:22 +0000 "GET /index.php" 301
nginx_1         | 172.23.0.1 - - [18/Aug/2017:12:41:22 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0" "-"

Então eu acho que, por algum motivo, o nginx faz um redirecionamento 301 para a porta 80. Você tem alguma ideia de por que isso acontece?

Editar 1

Eu também tentei configurar a porta 8080 na configuração nginx também:

Configuração do Nginx:

server {
  listen 8080;
  root /var/www/html;
  index index.php;

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

  location ~ .php{
    try_files $uri =404;
    fastcgi_pass wordpress:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    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  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  DOCUMENT_ROOT      $document_root;
    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_intercept_errors  on;
  }
}

docker-compose.yml:

version: '2'
    services:
      nginx:
        image: nginx:alpine
        ports:
          - "8080:8080"
        volumes:
          - './conf/nginx/:/etc/nginx/conf.d/:ro'
        links:
          - "wordpress"
        volumes_from:
          - "wordpress:ro"

      wordpress-db:
        image: mariadb
        environment:
          MYSQL_RANDOM_ROOT_PASSWORD: "yes"
          MYSQL_ONETIME_PASSWORD: "yes"
          MYSQL_DATABASE: "wordpress"
          MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
          MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'

      wordpress:
        build:
          context: .
          dockerfile: Dockerfile
        image: ellakcy/wordpressswithplugins:alpine
        links:
          - wordpress-db
        environment:
            WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
            WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
            WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
            WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
            WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
            WORDPRESS_URL: '${WORDPRESS_URL}'

Eu ainda tenho o mesmo comportamento.

Editar 2

Eu também tentei usar as seguintes configurações nginx (para o container nginx)

server {
  listen 8080;
  root /var/www/html;
  index index.php;

  location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  location ~ .php {
    try_files $uri =404;
    fastcgi_pass wordpress:9000;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    include fastcgi_params;
    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  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  DOCUMENT_ROOT      $document_root;
    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_intercept_errors  on;
  }

}

E ainda não vejo luz no meu caminho.

    
por Dimitrios Desyllas 18.08.2017 / 14:56

0 respostas