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

Deploy at non root URL #253

Open
viharm opened this Issue Aug 10, 2017 · 10 comments

Comments

Projects
None yet
6 participants
@viharm
Copy link

viharm commented Aug 10, 2017

This seems like a very good application. Thank you for efforts in creating this app. I respect the vision and agree with it.

I am trying to deploy this behind in existing environment which has an Apache installation serving several websites.

I would like to use my Apache webserver as a reverse proxy to access paperless. However I am also deploying this at a non-root URL of an existing virtual host, e.g., https://mydomain.tld/paperless

When I setup the reverse proxy, the Django service keeps throwing back the root URL, thus failing. Is there a configuration for setting this path/URL?

Regards.

@viharm viharm changed the title Deploye at non root URL Deploy at non root URL Aug 10, 2017

@danielquinn

This comment has been minimized.

Copy link
Collaborator

danielquinn commented Aug 14, 2017

I've never done something like that before, but a cursory search online pointed me to FORCE_SCRIPT_NAME which might be your best bet.

I suggest editing paperless/settings.py and adding FORCE_SCRIPT_NAME = "paperless" to the bottom and restarting the server to see if that works. If it does, issue a pull request that follows the other settings vars use of environment variables and I'll roll it into master.

If it doesn't work however, I'm afraid I don't know how to do that :-( I'm not opposed to making it work though, should someone else know how to do it.

@MasterofJOKers

This comment has been minimized.

Copy link
Contributor

MasterofJOKers commented Aug 14, 2017

I only know how to do this for deployments using uWSGI. This is part of my nginx config for another project:

location /blog/ {
                uwsgi_pass      127.0.0.1:8780;
                include         uwsgi_params;
                uwsgi_param SCRIPT_NAME /blog;
                # tell uwsgi to remove SCRIPT_NAME from the URL
                uwsgi_modifier1 30;
        }

Googling for SCRIPT_NAME, it seems also possible to set this as environment variable for django in a wsgi file. But that setting sounds like it should do the job.

@kmlucy

This comment has been minimized.

Copy link

kmlucy commented Jan 14, 2018

I run my instance at /paperless/. I run in docker, so I just run this before it starts to modify the necessary hardcoded URLs:

sed -i 's=/fetch=/paperless/fetch=' /usr/src/paperless/src/documents/admin.py
sed -i -e 's=/admin/login=/paperless/admin/login=' -e 's=/static/=/paperless/static/=' -e 's=/media/=/paperless/media/=' /usr/src/paperless/src/paperless/settings.py
sed -i -e 's=r"^=r"^paperless/=' -e 's=r"admin=r"paperless/admin=' -e 's=r""=r"paperless"=' /usr/src/paperless/src/paperless/urls.py

It's not the cleanest way, but it does work.

@danielquinn

This comment has been minimized.

Copy link
Collaborator

danielquinn commented Apr 13, 2018

Hi guys, I finally got around to fixing this tonight -- I hope -- your own responses will help determine if that's true ;-) Just do a git pull to get the changes.

@kmlucy, thanks to your URL hack above, I was able to track down all of the hard-coded URLs and replace them with properly named ones. Hopefully that will clean things up for you. @ovv's advice in #323 about configuring Nginx however may still be necessary. YMMV.

Assuming this works out, would any of you care to write some documentation about how you've made Paperless work on a subfolder?

@ovv ovv referenced this issue Apr 13, 2018

Open

Django runserver #329

@kmlucy

This comment has been minimized.

Copy link

kmlucy commented Apr 14, 2018

I updated Paperless, removed my URL hack, and updated my NGINX config. Now I am getting a DisallowedRedirect error when I try to navigate to URL.com/paperless.

Environment:


Request Method: GET
Request URL: http://URL.com/paperless/

Django Version: 1.11.12
Python Version: 3.6.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_extensions',
 'documents.apps.DocumentsConfig',
 'reminders.apps.RemindersConfig',
 'paperless_tesseract.apps.PaperlessTesseractConfig',
 'flat_responsive',
 'django.contrib.admin',
 'rest_framework',
 'crispy_forms',
 'django_filters']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'paperless.middleware.Middleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/usr/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/lib/python3.6/site-packages/django/core/handlers/base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "/usr/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/usr/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/lib/python3.6/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/usr/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/usr/lib/python3.6/site-packages/django/views/generic/base.py" in get
  193.                 return http.HttpResponsePermanentRedirect(url)

File "/usr/lib/python3.6/site-packages/django/http/response.py" in __init__
  431.             raise DisallowedRedirect("Unsafe redirect to URL with protocol '%s'" % parsed.scheme)

Exception Type: DisallowedRedirect at /
Exception Value: Unsafe redirect to URL with protocol 'admin'
@danielquinn

This comment has been minimized.

Copy link
Collaborator

danielquinn commented Apr 16, 2018

@kmlucy yeah I screwed that one up -- I don't know how to make it work for people running paperless on a subdirectory, sorry.

I've reverted that one line to the hard-coded redirect to /admin/, so you'll need to apply that patch to run it until someone sends me a PR that will make it work.

@kmlucy

This comment has been minimized.

Copy link

kmlucy commented Apr 16, 2018

@danielquinn No worries. My way works for me just fine, it just isn't very portable. If somebody figures out a cleaner way to do it, that's great, but no rush from my end. I looked into it a little, but it's outside my abilities.

@apiontek

This comment has been minimized.

Copy link

apiontek commented Sep 2, 2018

I'm not using docker as in #353 but I am using gunicorn with a unix socket, with paperless-2.1.0

I was able to get this working up to a point. I have:

PAPERLESS_FORCE_SCRIPT_NAME=/papers
PAPERLESS_STATIC_URL="/papers/static/"

And my nginx proxy code is:

# paperless
location /papers {
    proxy_pass http://unix:/tank/srvdata/paperless/paperless.sock;
    proxy_set_header Host $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;
}
location /papers/static {
    autoindex on;
    alias /tank/srvdata/paperless/paperless-2.1.0/static;
}

This works for loading the site and signing in. However when I add my first document, it won't load thumbnails. I get 404 errors on https://example.com/papers/fetch/thumb/1

I tried setting PAPERLESS_MEDIA_URL="/papers/media/" in case that was needed but it didn't fix the issue; I'm not clear what that setting is for or how to use it.

I tried the PAPERLESS_MEDIA_URL along with adding the following to nginx:

location /papers/media {
    autoindex on;
    alias /tank/srvdata/paperless/media;
}

Still no luck, though that was just guesswork. Any ideas?

EDIT TO ADD: with the above configuration the django error on directly trying to access https://example.com/papers/papers/fetch/thumb/1 is:

Using the URLconf defined in paperless.urls, Django tried these URL patterns, in this order:

^api/auth/
^api/
^fetch/(?Pdoc|thumb)/(?P\d+)$ [name='fetch']
^push$ [name='push']
admin/
^$
^papers/media/(?P.*)$

The current path, papers/fetch/thumb/1, didn't match any of these.

@massaquah

This comment has been minimized.

Copy link

massaquah commented Sep 8, 2018

I am trying to solve this, too.

Any news here?

@danielquinn

This comment has been minimized.

Copy link
Collaborator

danielquinn commented Sep 9, 2018

The blocker/solution appears to be #353, as it's most of the way there, but there's still a problem with the handling of static files. I'm afraid I have no idea how to solve it, but if someone can come up with a solution that I can reproduce, I'll gladly merge it.

@ovv ovv referenced this issue Nov 3, 2018

Closed

Apache SSL conf #434

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.