Configuration problem: request default 15.15.15.15/ not working

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Configuration problem: request default 15.15.15.15/ not working

wld75
I'm testing Nginx with a django application, the requests
https://15.15.15.15/admin/ and https://15.15.15.15/inicio/ work correctly,
but https://15.15.15.15/ throw error "Not found: The requested URL / was not
found on this server. ", And I can not find the error. This is the
configuration:

server{
       #Configuracion SSL

    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name 15.15.15.15;
    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;
   
    #root /home/gela/LibrosWeb;
   
    location = /favicon.ico { access_log off; log_not_found off; }
    location  /robots.txt { alias /var/www/LibrosWeb/robots.txt ;}
   
    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
   
    location /static {
        alias /home/gela/LibrosWeb/static;
    }
}
   
server{
    #Configuracion http
   
    listen 80;
    listen [::]:80;
    server_name 15.15.15.15;
    return 301 https://$server_name$request_uri;
}

and urls.py django:

urlpatterns = [
    path('', RedirectView.as_view(url='/inicio/', permanent=True)),
    path('inicio/', include('inicio.urls')),
    path('admin/', admin.site.urls),
]

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281393,281393#msg-281393

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

RE: Configuration problem: request default 15.15.15.15/ not working

Reinis Rozitis
> but https://15.15.15.15/ throw error "Not found: The requested URL / was not
> found on this server. ", And I can not find the error. This is the
> configuration:
> and urls.py django:
>
> urlpatterns = [
>     path('', RedirectView.as_view(url='/inicio/', permanent=True)),
>     path('inicio/', include('inicio.urls')),
>     path('admin/', admin.site.urls),
> ]


The error is coming from your py script and it actually tells what is the problem - the '/' url is not handled, so you probably need to add:

path('/', RedirectView.as_view(url='/inicio/', permanent=True)),

or location = / {} redirect in nginx.

rr

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: RE: Configuration problem: request default 15.15.15.15/ not working

wld75
I've also tried adding "/" and throwing the same error. I have also added to
the .conf file:

location = / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
}

before the fragment location / {......} with the same error.
This error is very strange. The configuration is very simple, but I can not
find the problem.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281393,281411#msg-281411

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

RE: RE: Configuration problem: request default 15.15.15.15/ not working

Reinis Rozitis
> I've also tried adding "/" and throwing the same error. I have also added to the
> .conf file:
>
> location = / {
>         include proxy_params;
>         proxy_pass http://unix:/run/gunicorn.sock; }
>
> before the fragment location / {......} with the same error.
> This error is very strange. The configuration is very simple, but I can not find the
> problem.

Again the error is not coming from nginx but your backend (you either didn't add the "/" handling in the right place or maybe didn't restart the gunicorn workers afterwards).

The configuration change you made doesn't make any difference in the way nginx operated before, what I meant was something like this:

location = / {
        return 301 /inicio/;
}


Obviously this is just a workaround and if you can manage to fix the backend this location block is not needed.

rr

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Configuration problem: request default 15.15.15.15/ not working

wld75
In reply to this post by wld75
Effectively it was necessary to restart gunicorn every time that I modify
the file urls.py so that the changes take effect. I did not know that. I did
it like that:


$ systemctl daemon-reload
$ systemctl restart gunicorn


Thanks for the help.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281393,281423#msg-281423

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx