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

Creating new user, work, collection etc. fails when using nginx reverse proxy and certbot SSL #134

Open
bellisk opened this issue Apr 19, 2024 · 1 comment
Labels
bug Something isn't working documentation Improvements or additions to documentation reviewed v0.6.0

Comments

@bellisk
Copy link
Contributor

bellisk commented Apr 19, 2024

Describe the bug
I've deployed my own Ourchive instance following the steps described here, including setting up SSL using certbot and an nginx reverse proxy. POST requests to the site (e.g. creating a new user or new work) were not successful, even after working around #131. No errors were logged.

After some debugging, this turned out to be because the nginx config from certbot redirects all requests from http://example.org to https://example.org with a 301 response, which browsers generally respond to by transforming the request method to GET.

The problem here is that this seems to be happening all the time. Although I am visiting my Ourchive site with the https:// url, every request is first accepted as an http request and a 301 response is returned. The subsequent request to the https:// url then uses the GET method. This meant that no POST requests were working at all.

I have solved this for now by adjusting the nginx config to redirect with a 308 response code, which doesn't change the request method on redirect. This might be more of an nginx issue (?) but I thought it was worth reporting anyway.

To Reproduce

  1. Deploy Ourchive to VPS hosting and set up nginx and SSL as described in https://docs.getourchive.io/admin-getting-started/
  2. Try to create a new user or a new work as a logged-in user
  3. Creation will fail

Expected behavior
Creating a new user, new work, etc. should succeed.

Desktop (please complete the following information):

  • OS: Linux Mint
  • Browser: Firefox
  • Version: 124

Hosting
Digital Ocean droplet running Ubuntu 22.04.

Additional context
nginx config:

server {
    client_max_body_size 300M;
    server_name example.org;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/ourchive/ourchive/ourchive_app;
    }
    
    # assumes a media folder at /mnt/ourchive-volume/media
    location /media/ {
        root /home/ourchive;
    }


    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ourchive/ourchive/ourchive_app/ourchive_app.sock;
	add_header X-Robots-Tag "noindex, nofollow";
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

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


    listen 80;
    server_name example.org;
    return 404; # managed by Certbot
}

Example logs:

urllib3.connectionpool DEBUG 2024-04-19 18:01:54,973 connectionpool 14728 139836487703328 Starting new HTTP connection (1): example.org:80
urllib3.connectionpool DEBUG 2024-04-19 18:01:54,980 connectionpool 14728 139836487703328 http://example.org:80 "POST /api/works/ HTTP/1.1" 301 178
urllib3.connectionpool DEBUG 2024-04-19 18:01:54,981 connectionpool 14728 139836487703328 Starting new HTTPS connection (1): example.org:443
urllib3.connectionpool DEBUG 2024-04-19 18:01:55,074 connectionpool 14728 139836487703328 https://example.org:443 "GET /api/works/ HTTP/1.1" 200 102
@c-e-p
Copy link
Collaborator

c-e-p commented Apr 22, 2024

@bellisk Definitely worth reporting, thank you. I'll check my own nginx config and at minimum we can add some documentation about how best to configure this. Our goal with v1 is to support more guided/low-friction installs which means this kind of config will have to be standardized/documented anyway.

@c-e-p c-e-p added bug Something isn't working documentation Improvements or additions to documentation labels Apr 22, 2024
@c-e-p c-e-p added the reviewed label May 9, 2024
@c-e-p c-e-p added the v0.6.0 label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation reviewed v0.6.0
Projects
None yet
Development

No branches or pull requests

2 participants