Problem serving Django "polls" tutorial under lighttpd: 404 page not found

I am following the Django polls tutorial, which is working 100% with the built-in development server (python3 manage.py runserver).

I have set up lighttpd to serve django through UWSGI and that seems to be working fine but for one glitch: the URL passed to django seems to have been modified.

My lighttpd configuration is basically this:

...
server.modules += ("mod_scgi","mod_rewrite")
scgi.protocol = "uwsgi"
scgi.server   = (
    "/polls" => ((
             "host" => "localhost",
             "port" => 7000,
             "check-local" => "disable",
    ))
)

The Django tutorial mapping looks like:

# tutorial1/urls.py
urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

# polls/urls.py
app_name = 'polls'
urlpatterns = [
    path('', views.IndexView.as_view(), name='index'),
    path('<int:pk>/', views.DetailView.as_view(), name='detail'),
    path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
    path('<int:question_id>/vote/', views.vote, name='vote'),
]

However when I hit http://localhost:8080/polls/ in the address bar, it produces an 404 error.

enter image description here

If I add an extra /polls to the URL then it works just fine.

enter image description here

enter image description here

My goal with this exercise is to be able to serve this app switching from and to both servers without needing to modify configuration files each time.

What do I need to do on the lighttpd.conf side to make lighttpd interchangeable with Django's own internal dev server?

I have tried to add the following url.rewrite rule but it messes up completely the URL handling.

url.rewrite = (
    "^/polls/(.*)$" => "/polls/polls/$1"
)

Thank you!

Have you tried using an empty string? (It's a not a proper answer to the question but I can't make a comment)

scgi.server   = (
    "" => ((
             "host" => "localhost",
             "port" => 7000,
             "check-local" => "disable",
    ))
)
Back to Top