Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix proxy_pass location / for docker nginx #102

Open
cenobitz opened this issue May 16, 2023 · 2 comments
Open

Fix proxy_pass location / for docker nginx #102

cenobitz opened this issue May 16, 2023 · 2 comments

Comments

@cenobitz
Copy link

cenobitz commented May 16, 2023

https://github.com/bookwyrm-social/documentation/blob/main/content/running_bookwyrm/reverse-proxy.md
in docker-compose.yml is:

version: '3'

services:
  nginx:
    image: nginx:latest
    restart: unless-stopped
    ports:
       - "8001:8001"

so in nginx should be not 8000 but:

    location / {
        proxy_pass http://localhost:8001;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
    }
@Sebastix
Copy link

When I do that, I got a 502 error from nginx

*2665 connect() failed (111: Connection refused) while connecting to upstream, client: 92.70.xxx.xxx, server: books.sebastix.social, request: "GET /setup HTTP/1.1", upstream: "http://127.0.0.1:8001/setup"

@cenobitz
Copy link
Author

cenobitz commented Sep 6, 2023

docker-compose.yml

version: '3'

services:
  nginx:
    image: nginx:latest
    restart: unless-stopped
    ports:
       - "8001:8001"
    depends_on:
      - web
    networks:
      - main
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - static_volume:/app/static
      - media_volume:/app/images
  db:
    image: postgres:13
    env_file: .env
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - main
  web:
    build: .
    env_file: .env
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/app
      - static_volume:/app/static
      - media_volume:/app/images
    depends_on:
      - db
      - celery_worker
      - redis_activity
    networks:
      - main
    ports:
      - "8000"

in bookwyrm /nginx/default.conf

include /etc/nginx/conf.d/server_config;

upstream web {
    server web:8000;
}

in /etc/nginx/sites-enabled/book.yourdomain.com

server {
    if ($host = book.yourdomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name book.yourdomain.com;

    listen [::]:80;
    listen 80;
    add_header Strict-Transport-Security "max-age=31536000;includeSubDomains" always;
    location / { return 301 https://$host$request_uri; }


}

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;

    # SSL code
    ssl_certificate /etc/letsencrypt/live/book.yourdomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/book.yourdomain.com/privkey.pem; # managed by Certbot

    server_name book.yourdomain.com;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    location / {
        proxy_pass http://localhost:8001;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
    }

    location /images/ {
        proxy_pass http://localhost:8001;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
    }

    location /static/ {
        proxy_pass http://localhost:8001;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
    }

}

This is working for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants