python - Can a WSGI application tell the web server serving it to send its default HTTP 404 error page? -
i have bare wsgi application in module called app
(app.py) looks this:
def application(environ, start_response): path = environ['path_info'] if path == '/': start_response('200 ok', [('content-type','text/html')]) return [b'<p>it works!</p>\n'] elif path == '/foo': start_response('200 ok', [('content-type','text/html')]) return [b'<p>hello world</p>\n'] else: start_response('404 not found', [('content-type','text/html')]) return [b'<p>page not found</p>\n']
i serving app using nginx + uwsgi configuration.
nifty:/www# cat /etc/nginx/sites-enabled/myhost server { listen 8080; root /www/myhost; index index.html index.htm; server_name myhost; location / { uwsgi_pass 127.0.0.1:9090; include uwsgi_params; } }
i start uwsgi command:
uwsgi --socket 127.0.0.1:9090 --module app
the app behaves expected:
debian:~# curl -i http://myhost:8080/ http/1.1 200 ok server: nginx/1.4.4 date: mon, 24 mar 2014 13:05:51 gmt content-type: text/html transfer-encoding: chunked connection: keep-alive <p>it works!</p> debian:~# curl -i http://myhost:8080/foo http/1.1 200 ok server: nginx/1.4.4 date: mon, 24 mar 2014 13:05:55 gmt content-type: text/html transfer-encoding: chunked connection: keep-alive <p>hello world</p> debian:~# curl -i http://myhost:8080/bar http/1.1 404 not found server: nginx/1.4.4 date: mon, 24 mar 2014 13:05:58 gmt content-type: text/html transfer-encoding: chunked connection: keep-alive <p>page not found</p>
however, not happy http 404 'page not found' response. want when wsgi app wants send http 404 response, default http 404 error page of nginx sent client.
here how default http 404 response of nginx looks like. note response below default virtual host (not myhost
virtual host used in examples above). default virtual host doesn't have wsgi application , hence able see default http 404 error page of nginx in output below.
debian:~# curl -i http://localhost:8080/bar http/1.1 404 not found server: nginx/1.4.4 date: mon, 24 mar 2014 13:06:06 gmt content-type: text/html content-length: 168 connection: keep-alive <html> <head><title>404 not found</title></head> <body bgcolor="white"> <center><h1>404 not found</h1></center> <hr><center>nginx/1.4.4</center> </body> </html> debian:~#
is there way wsgi application tell web server serving send http 404 response client?
note:
- i want solution web-server agnostic, i.e. shouldn't have hard-code web server's http 404 page in code or template, or shouldn't have read html specific nginx. solution should work on nginx or other web-server apache, lightttpd, etc.
- i aware 1 should using wsgi framework actual web development. going settle bottle.py before doing so, trying understand capabilities , limitations of wsgi know going on behind scenes when use bottle.
from discussion in comments section, answer seems be:
no!
Comments
Post a Comment