Internal Server Error on access via HTTPS to a Django application - django

I'm trying to make an access to my Django application by HTTPS.
In the config.py of the project I has set the key
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
On my configuration to serve all I've an Apache 2.4 so I've create the right entry into "sites-availables" directory, obviously followed by a2ensite, I've generate my own SSL Key (.crt and .key files), changed ownership and permission, restared apache2.
When I try to access to the site I got the follow error message
"""
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at webmaster#localhost to
inform them of the time this error occurred, and the actions you
performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.7 (Ubuntu) Server at inno Port 9443
"""
I've take a look into /var/log/apache2/error.log but there's nothing, on /var/log/apache2/access.log I've found
xxx.xxx.xxx.xxx - - [25/May/2016:12:29:36 +0200] "GET /favicon.ico
HTTP/1.1" 500 996 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64;
rv:46.0) Gecko/20100101 Firefox/46.0"
There are someone that can give me some hint?
Thanks a lot
Carlos

It looks like your virtual host within apache isnt properly configured so it's not handling php files the way it should. I guess you should use a handler directive in order to tell apache to handle all .php files and most probably your issue will be fixed. This is the maximum that can be done since you didn't provide much info about the error.

Related

Nginx config for Contact Form via AWS/Lambda/SES/API Gateway

I have been following this tutorial on how to configure my contact form using AWS Lambda/SES/API Gateway
https://www.freecodecamp.org/news/how-to-receive-emails-via-your-sites-contact-us-form-with-aws-ses-lambda-api-gateway/
I am successfully able to test with the deployed Lambda code but he doesn't explain the Nginx/Webserver configuration part. Not sure if this is the correct way but I have tried to have the Contact form POST to the AWS lambda function but Nginx keeps appending my root directory namely /usr/share/nginx/html
Here is the Nginx log:
[error] 29#29: *10 open() "/usr/share/nginx/html/contact/<https:/xxxxxxxxx.execute-api.us-east-1.amazonaws.com/default/SendContactEmail>" failed (2: No such file or directory), client: <ip address>, server: www.website.net, request: "POST /contact/%3Chttps://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/default/SendContactEmail%3E HTTP/2.0", host: "www.website.net", referrer: "https://www.website.net/contact/"
"POST /contact/%3Chttps://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/default/SendContactEmail%3E HTTP/2.0" 404 548 "https://www.website.net/contact/"
I realize the issue is with location tag in Nginx config but I'm trying to figure out what I'm doing wrong here.
location /contact/ {
proxy_set_header Host $proxy_host;
proxy_ssl_server_name on;
}
When I hit the Submit button it should try to contact the AWS Lambda function but instead it gives a 404 not found message because Nginx has the wrong path.
I found the issue, The javascript code for endpoint did not need the brackets <> . Once I removed that, it all started working as it should.

localhost:8000 working but mywebsite:8000 with etc/hosts modified doesn't work

Everything is in the title: I'm launching my webserver (Django / Python) on port 8000.
/home/olivier/my_venv3.8/bin/python3 /home/olivier/pycharm-2018.1.3/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 40761 --file /home/olivier/projects/evalr/manage.py runserver 8000
pydev debugger: process 5923 is connecting
Connected to pydev debugger (build 193.5662.61)
http://evalr.hqf.fr:8000/fr/assistant/
http://evalr.hqf.fr:8000/fr/sessions/
pydev debugger: process 5935 is connecting
http://evalr.hqf.fr:8000/fr/assistant/
http://evalr.hqf.fr:8000/fr/sessions/
Watching for file changes with StatReloader
Performing system checks...
I've added in my /etc/hosts this line : 127.0.1.1 evalr.hqf.fr and when I ping it, it correctly shows "127.0.0.1"
When I try go on http://evalr.hqf.fr:8000 I get connection refused and when I try to go on http:/localhost:8000 it works.
The problem is that when I try to go on http://evalr.hqf.fr:8000 I dont have any trace on the server side, i.e. it stays here:
System check identified no issues (0 silenced).
January 03, 2020 - 20:41:31
Django version 3.0.2, using settings 'evalr.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
And when I go on http://127.0.0.1:8000/ I get a log of every single access like:
[03/Jan/2020 20:47:42] "GET /fr/sessions/ HTTP/1.1" 302 0
[03/Jan/2020 20:47:42] "GET /fr/login/?next=/fr/sessions/ HTTP/1.1" 200 7031
[03/Jan/2020 20:47:43] "GET /static/vendors/css/all.min.css HTTP/1.1" 200 54456
................ blabla............;
[03/Jan/2020 20:47:43] "GET /favicon.ico HTTP/1.1" 301 0
I've even tried to reboot (even though I'm on Linux, which talks by itself - no reboot needed), so I'm stuck because everything should work fine. What am I missing?
That is because in /etc/hosts it should be 127.0.0.1 instead
Also check the ALLOWED_HOSTS and you could try running it with: python manage.py runserver 0.0.0.0:8000
The fact that you get a connection refused when using the hostname, and do not see any logging from your application, makes me think that you are dealing with DNS caching. My favorite way to test this is using curl, since it can show you both the IP address and response of an HTTP request. Try the following command:
curl -Iv -X GET http://evalr.hqf.fr:8000
Did it resolve to 127.0.0.1? If so, did you get a response? If so, did you see logs in your application?
If the answer to these question is yes, then try to clear the DNS and browser cache.

ngrok doesn't lift my local django web server

I have problems with negrok, it does not raise my local django web server, a few days ago everything worked correctly but a normal day, without having touched anything, it stopped working.
Run the following:
python manage.py runserver
Everything works normally and correctly.
Now I execute the following, in order to raise the local django server:
./ngrok http 8000
ngrok runs correctly without any problem but when accessing the ngrok link, the page is loading and everything is blank and does not work ....
This appears in ngrok:
ngrok by #inconshreveable (Ctrl+C to quit)
Session Status online
Account Julio (Plan: Free)
Version 2.3.34
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://33822c5a.ngrok.io -> http://localhost:8000
Forwarding https://33822c5a.ngrok.io -> http://localhost:8000
Connections ttl opn rt1 rt5 p50 p90
2 0 0.03 0.01 0.20 0.21
HTTP Requests
-------------
GET / 400 Bad Request
GET / 400 Bad Request
And this appears in django:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
September 25, 2019 - 17:23:19
Django version 2.2.2, using settings 'ibme_proyect.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Invalid HTTP_HOST header: '33822c5a.ngrok.io'. You may need to add '33822c5a.ngrok.io' to ALLOWED_HOSTS.
Bad Request: /
[25/Sep/2019 17:25:30] "GET / HTTP/1.1" 400 68119
Invalid HTTP_HOST header: '33822c5a.ngrok.io'. You may need to add '33822c5a.ngrok.io' to ALLOWED_HOSTS.
Bad Request: /
[25/Sep/2019 17:25:38] "GET / HTTP/1.1" 400 68254
I add the ngrok host (33822c5a.ngrok.io) in ALLOWED_HOSTS and stop giving django error, and access the ngrok link and I know that it loads again, it doesn't load the HTML, nothing, everything blank ...
Any solution? :(
try
ALLOWED_HOSTS = ["*"]
this will allow tunneling every ngrok run :)

Nginx Bad Gateway with Django Social Auth and uwsgi

My site is running correctly locally (using the built in runserver), but when running with nginx and uwsgi, I'm getting a Bad Gateway (502) during the django-social-auth redirect.
The relevant nginx error_log:
IPREMOVED - - [11/Oct/2012:12:10:18 +1100] "GET /complete/google/? ..snip .. HTTP/1.1" 502 574 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.26 Safari/537.11"
The uwsgi log:
invalid request block size: 4204 (max 4096)...skip
Thu Oct 11 12:16:46 2012 - error parsing request
Refreshing the Bad Gateway response redirects and logs in correctly. This happens every single time. The nginx and uwsgi logs here have different timing as they were separate requests. The logs are consistent.
This is the first time deploying django to nginx for me, so I'm at a loss as to where to start.
Have you tried increasing the size of the uwsgi buffer:
-b 32768
http://comments.gmane.org/gmane.comp.python.wsgi.uwsgi.general/1171

Django runserver shows HTTP

I have configured nginx to run HTTPS. I also rewrite all the rules so it's running under HTTPS.
But is it true that Django still runs with HTTP internally?
Django version 1.2.1, using settings 'myproject.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[14/Aug/2012 23:57:04] "GET /app/c HTTP/1.0" 200 4
[14/Aug/2012 23:57:09] "GET /app/c HTTP/1.0" 200 4
Yes. I know my version is way way way outdated.
I checked request.is_secure and it returns True as I am accessing HTTPS.
Correct, internally you will use http to communicate through your proxy server but all your external traffic will use the https method.
To further secure your traffic ensure that you only bind to a local address, or alternatively use a socket to connect between nginx and your application server.
I do hope that you're not using django's development server in production, you should instead use something like gunicorn as your application server.