strapi / strapi-docker

Install and run your first Strapi project using Docker
https://strapi.io
MIT License
1.16k stars 447 forks source link

404 when attempting to access admin panel behind reverse proxy #280

Closed eric-at-nocoast closed 3 years ago

eric-at-nocoast commented 3 years ago

Going to preface this with the fact that I'm very new to working with Docker so it's very possible I'm missing something, any help would be appreciated.

After building an image using the example Dockerfile behind a reverse proxy, I receive a 404 when trying to access the admin panel.

Admin path

Additionally though the index page loads, it is missing the "Create admin" button

rootpath

Dockerfile:


FROM strapi/base

WORKDIR /srv/app

COPY ./app/package.json ./
COPY ./app/yarn.lock ./

RUN yarn install

COPY ./app /srv/app

ENV NODE_ENV production

RUN yarn build

EXPOSE 1337
CMD ["yarn", "start"] 

Docker-compose.yml

version: "3"

services:
  strapiscribbler:
    build: .
    container_name: strapiscribbler
    restart: unless-stopped
    env_file: .env
    environment:
      DATABASE_CLIENT: ${DATABASE_CLIENT}
      DATABASE_NAME: ${DATABASE_NAME}
      DATABASE_HOST: ${DATABASE_HOST}
      DATABASE_PORT: ${DATABASE_PORT}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
    #    links:
    #      - mongo:mongo
    networks:
      - strapi-app-network
    volumes:
      - ./app:/srv/app
    ports:
      - "1337:1337"

  mongoscribbler:
    image: mongo
    container_name: mongoscribbler
    restart: unless-stopped
    env_file: .env
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
    networks:
      - strapi-app-network
    volumes:
      - strapimongo:/data/db
    ports:
      - "27017:27017"

networks:
  strapi-app-network:
    driver: bridge

volumes:
  strapimongo:

config/server.js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  url:  'https://example.dev/api',
  admin: {
     auth: {
      secret: env('ADMIN_JWT_SECRET', 'super secret'),
    },
  url:  'https://example.dev/author',
  },
});

nginx.conf

server {
    # Listen HTTP
    listen 80;
    server_name example.dev;

    # Redirect HTTP to HTTPS
    return 301 https://$host$request_uri;
}

server {
    # Listen HTTPS
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.dev;

    # SSL config
     ssl_certificate /etc/path/certificate
     ssl_certificate_key /etc/path/certificatekey 

    # Static Root
    location / {
        root /var/www/html;
        index index.html;
        try_files $uri /200.html = 404;
    }
    # Strapi API
    location /api/ {
        rewrite ^/api/(.*)$ /$1 break;
        proxy_pass http://strapi;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }

    # Strapi Dashboard
    location /author {
        proxy_pass http://strapi/author;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }
}

upstream.conf


# Strapi server
upstream strapi {
    server 127.0.0.1:1337;
}
artfurma commented 3 years ago

Hi, I'm running into the exact same issue. Have you managed to resolve it?

eric-at-nocoast commented 3 years ago

Hey @artfurma,

I had to switch to a subdomain approach to get this functioning. I couldn't get the sub folder approach to function with the application being dockerized.

Serverfrog commented 1 year ago

@eric-at-zd so basically, this is still a bug and you just switched away from this approach of sub folder. So this should still be an issue? Because im having the same problem and either the official Strapi documentation is faulty or incomplete