ubuntu+nginx+django urlpatterns 404 not found

1,273 views
Skip to first unread message

minom du

unread,
May 8, 2016, 9:40:40 AM5/8/16
to Django users
Hello ,every body.
attachment is my code

i set the urls.py below 
urlpatterns += patterns('bullet.views.noticeview',
(r'^$', 'notice'),
(r'^board', 'board'),
)

the urlpatterns ^$ work fine
but ^board not work ,it show 404 not found

i have some code like this but work on windows+apache
it work fine

now i move it to ubuntu+nginx
then it not work

anyone can tell me how fix it ,please
thank you very much
school.zip

Gergely Polonkai

unread,
May 8, 2016, 1:36:49 PM5/8/16
to Django users

What do you mean it doesn't work? What error message you get? Are you sure it is provided by Django and not the webserver?

Also, GMail is marking your message as a possible malware; consider pasting your urls.py inline instead of an attachment.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/48902712-26b6-4f3a-b465-ab4699f4dbfb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

minom du

unread,
May 9, 2016, 4:05:59 AM5/9/16
to Django users
sorry,my english is not good
my urls.py is
from django.conf.urls import include, url, patterns
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
]

urlpatterns += patterns('bullet.views.noticeview',
(r'^$', 'notice'),
(r'^board', 'board'),
)

and this is my views code
def notice(request):
logger = logging.getLogger('school')
logger.info("ko ")
board_list=board.objects.using("default").all()
return render_to_response('index.html',locals())

def board(request):
t = loader.get_template("index.html")
response_data = {}
response_data["result"] = "Y"
board_list=board.objects.using("default").all()
response_data["content_html"] = t.render(Context({'board_list':board_list}))
return HttpResponse(json.dumps(response_data), content_type="application/json")

when i run localhost:82 it will run notice and goto index.html
but when i run localhost:82/board
it will return 404 not found

and i try to change the code def board to this
def board(request):
logger = logging.getLogger('school')
logger.info("ko ")
board_list=board.objects.using("default").all()
return render_to_response('index.html',locals())

just same of notice 
it still return 404 not found

the environment is ubuntu+nginx+django 1.8.13


and i try build it on the environment windows2008+apache+django1.8.7
both notice and board can work fine(windows use port:83)



so i don't understand why ubuntu+nginx will return 404 not found








Gergely Polonkai於 2016年5月9日星期一 UTC+8上午1時36分49秒寫道:

minom du

unread,
May 9, 2016, 10:54:57 AM5/9/16
to Django users
now,i try to install apache on ubuntu
and run the same code
it can return correctly
but nginx still return 404 not found

Gergely Polonkai

unread,
May 9, 2016, 12:27:56 PM5/9/16
to Django users


On May 9, 2016 10:06, "minom du" <min...@gmail.com> wrote:
>
> sorry,my english is not good
> my urls.py is
> from django.conf.urls import include, url, patterns
> from django.contrib import admin
>
> urlpatterns = [
>     url(r'^admin/', include(admin.site.urls)),
> ]
>
> urlpatterns += patterns('bullet.views.noticeview',
> (r'^$', 'notice'),
> (r'^board', 'board'),
> )

patterns is going away soon, so try this instead:

urlpatterns = [
    url(r'^admin/', include(admin.sites.urls)),
    url(r'^$', 'notice'),
    url(r'^board', 'board'),
]

My guess is that it will solve your problem. If not, come back to us with the results!

> so i don't understand why ubuntu+nginx will return 404 not found
>
>
>
>
>
>
>
>
> Gergely Polonkai於 2016年5月9日星期一 UTC+8上午1時36分49秒寫道:
>>
>> What do you mean it doesn't work? What error message you get? Are you sure it is provided by Django and not the webserver?
>>
>> Also, GMail is marking your message as a possible malware; consider pasting your urls.py inline instead of an attachment.
>>>
>>>

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.

> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c23eb219-a5ba-4353-b938-79c478783921%40googlegroups.com.

minom du

unread,
May 9, 2016, 10:37:08 PM5/9/16
to Django users
 

thanks ,but it not fix the problem

i write same as your code first
but return 404 not found
so i try other code 

minom du

unread,
May 9, 2016, 10:46:12 PM5/9/16
to Django users
i use apache then it work
so i guess maybe my nginx setting wrong somewhere
below is my nginx+uwsgi setting

uwsgi.ini
[uwsgi]
vhost = true
project=school
base = /home/minom/project
plugins =http, python3
socket = /tmp/school.sock
master = true
enable-threads = true
processes = 4
wsgi-file =/home/minom/project/school/school/wsgi.py

chdir = /home/minom/project/school
module = %(project).wsgi:application

nginx default

server {
listen 82 default_server;
listen [::]:82 default_server;
client_max_body_size 4G;
charset utf-8;
root /home/minom/project/school/school;

      index index.html index.htm index.nginx-debian.html;

server_name _;

access_log /var/log/nginx/school.access.log;
        error_log /var/log/nginx/school.error.log;

location /static/ {
            autoindex on;
           alias   /home/minom/project/school/static/;
         }

location /_upload/ {
            autoindex on;
           alias   /home/minom/project/school/_upload/;
         }

location /templates {
            autoindex on;
           alias   /home/minom/project/school/templates/;
         }
 
location / {
uwsgi_pass unix://tmp/school.sock;
include uwsgi_params;
try_files $uri $uri/ =404;
}

}

uwsgi.xml

<uwsgi>
    <module>wsgi</module>
    <master>true</master>  
    <pidfile>/home/minom/project/School/school.pid</pidfile>
    <socket>127.0.0.1:9998</socket>
    <processes>5</processes>
    <uid>1000</uid> 
    <gid>2000</gid> 
    <harakiri>20</harakiri>
    <limit-as>128</limit-as>
    <max-requests>5000</max-requests>
    <vacuum>true</vacuum>
    <plugin>python3</plugin>
    <pythonpath>/home/minom/project/school/school</pythonpath>
    <logdate>true</logdate>
    <daemonize>/home/minom/project/school/school/uwsgi.log</daemonize>
</uwsgi>    




James Schneider

unread,
May 10, 2016, 1:09:32 AM5/10/16
to django...@googlegroups.com

when i run localhost:82 it will run notice and goto index.html
but when i run localhost:82/board
it will return 404 not found


You need to determine whether Django or Nginx is responding with the 404 error.

Do you have DEBUG = True in your settings.py?

What does the 404 error page look like? Assuming you haven't customized the 404 error page, the default Nginx 404 page is white, and actually says Nginx on it (http://i.stack.imgur.com/v8X8y.png). 

With DEBUG = True enabled in Django, you should receive the yellow Django error page that has more details relating to the error (hopefully). (http://i.stack.imgur.com/V2f7f.jpg)

Does /home/minom/project/school/school/uwsgi.log contain any useful information (or at least show the request was made)? If so, Django is to blame and we need to further examine your URL's/views.

Does /var/log/nginx/school.error.log contain any useful information? Nginx may secretly be complaining about something behind the scenes.

Does your other URL/view also return a 404? (http://localhost:82) If that one works, then the issue definitely lies with Django.

-James

minom du

unread,
May 10, 2016, 7:10:37 AM5/10/16
to Django users
thanks, i have DEBUG = True in my settings.py
the 404 error page is white,jsut like v8X8y.png
the school.access.log  show 404 209 
the school.error.log don't have any info for localhost:82/board
localhost:82 is work,but localhost:82/board return 404

James Schneider於 2016年5月10日星期二 UTC+8下午1時09分32秒寫道:

Sai K

unread,
May 10, 2016, 7:36:57 AM5/10/16
to Django users
Can you change the url for board some thing like : url(r'^board$', 'board') , lets try.

minom du

unread,
May 10, 2016, 7:51:22 PM5/10/16
to Django users
i tried
and still return 404 not found

Sai K於 2016年5月10日星期二 UTC+8下午7時36分57秒寫道:

Gergely Polonkai

unread,
May 11, 2016, 2:10:37 AM5/11/16
to Django users

If your 404 pages are white with DEBUG=True, then the problem lies within the web server config. Could you show us the working apache config, too?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

minom du

unread,
May 11, 2016, 7:03:33 AM5/11/16
to Django users
this is apache config
<VirtualHost *:8080>

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /static /home/minom/project/school/static
        <Directory /home/minom/project/school/static>
            Require all granted
        </Directory>
        WSGIScriptAlias / /home/minom/project/school/school/wsgi.py
WSGIDaemonProcess abc.com user=minom processes=2 threads=15
        WSGIProcessGroup abc.com
        <Directory /home/minom/project/school/school>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
    
</VirtualHost>



Gergely Polonkai於 2016年5月11日星期三 UTC+8下午2時10分37秒寫道:

James Schneider

unread,
May 14, 2016, 1:24:06 AM5/14/16
to django...@googlegroups.com
 
location / {
uwsgi_pass unix://tmp/school.sock;
include uwsgi_params;
try_files $uri $uri/ =404;
}

I have a feeling this section is what is causing you trouble. Do you have a separate "upstream <name> {}" section that you can use with uwsgi_pass?

Have you tried removing the try_files line? I haven't played with it personally, but it doesn't look correct at first glance according to the docs, I don't believe your request is ever being sent to uWSGI.


Have you taken a look at the uWSGI Django documentation page? It has a working (I'd assume) config: 


Use that config as a reference to assess your own.

-James

minom du

unread,
May 17, 2016, 8:02:03 PM5/17/16
to Django users
thank you very much
i remove the try_files line
and it work fine
thanks again

James Schneider於 2016年5月14日星期六 UTC+8下午1時24分06秒寫道:
Reply all
Reply to author
Forward
0 new messages