django - Configure apache to respond with error page for incorrect hosts -
django docs:
you should configure web server sits in front of django validate host. should respond static error page or ignore requests incorrect hosts instead of forwarding request django. way you’ll avoid spurious errors in django logs (or emails if have error reporting configured way). example, on nginx might setup default server return “444 no response” on unrecognized host:
i using apache , works:
http://serverip -> 404 error
http://www.example.com -> https://www.example.com -> django site
http://example.com -> https://example.com -> django site
now have problem https://serverip
not secure message browser because have ssl cert example.com, www.example.com , after accept security warning see django site want 404 error page. how can achieve or misunderstand django docs?
update config:
assume django site /var/www/html/index.html simplification
000-default.conf:
<virtualhost *:80> redirect 404 / </virtualhost>
example.com.conf:
<virtualhost *:80> serveradmin example@example.com servername example.com serveralias www.example.com documentroot /var/www/html errorlog ${apache_log_dir}/error.log customlog ${apache_log_dir}/access.log combined rewriteengine on rewritecond %{server_name} =www.example.com [or] rewritecond %{server_name} =example.com rewriterule ^ https://%{server_name}%{request_uri} [end,ne,r=permanent] </virtualhost>
example.com-le-ssl.conf:
<ifmodule mod_ssl.c> <virtualhost *:443> serveradmin example@example.com servername example.com serveralias www.example.com documentroot /var/www/html errorlog ${apache_log_dir}/error.log customlog ${apache_log_dir}/access.log combined sslcertificatefile /etc/letsencrypt/live/example.com/fullchain.pem sslcertificatekeyfile /etc/letsencrypt/live/example.com/privkey.pem include /etc/letsencrypt/options-ssl-apache.conf </virtualhost> </ifmodule>
Comments
Post a Comment