Why Nginx adds "?next=" for my URL on Django Web App?



My Django project has 5 apps: central, mails, insure, redbooks and dshop.


urlpatterns = [
    path('login/', auth_views.LoginView.as_view(template_name='central/login.html'), name='login'),
    path('logout/', auth_views.LogoutView.as_view(next_page='login'), name='logout'),
    path('home/', c_view.home, name='home'),
    path('mails/', include('mails.urls')),
    path('insure/', include('insure.urls')),
    path('redbooks/', include('redbooks.urls')),
    path('dshop/', include('dshop.urls')),
    path('adminpage/', admin.site.urls),

My Django project has been deployed on Digital Ocean.

How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 20.04

Run with

$ python manage.py runserver, WORKS FINE


$ gunicorn --bind lskweb.wsgi, WORKS FINE

But when Nginx starts with basic config:

sudo nano /etc/nginx/sites-available/lskweb

    server {
        listen 80;
        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /home/pawin/lskweb-ocean;
        location / {
            include proxy_params;
            proxy_pass http://unix:/home/pawin/lskweb-ocean.sock;

Nginx adds "?next=" in front of my Django URL.


  • instead of

  • instead of

But when I click on the browser and go back and click the link again sometime Nginx give the correct URL in one click and sometimes after multiple clicks.

Now, my landing page is (type in browser address box) and it is OK.

/static/ no problem its serv files OK.

This is my video , when i click any links


Thank you for your helps 🙂


This is caused by Django and not nginx.

you probably have @login_required() decorator on your view

When you have a page that requires a login and the user is not logged in, it will redirect you to the login page specified in your LOGIN_URL = 'login' (This is for mine) after the user logs in it’ll then redirect to the page the user was trying to go before.

like this:

it will redirect to the user dashboard after the user logs in.

Answered By – brian yeap

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More