Django API works locally but not when deployed on Elastic Beanstalk - django

I'm working with Django Rest Framework and Django Rest Framework JWT, but I'm running into an issue in regards to local behavior vs external behavior.
When I make a POST request to get a JWT token, everything works as desired both locally and on my EC2 instance. However, once I have the token, when I make a request to my server that requires authentication, only my local server returns the expected response. On my deployed server, I get the following error:
{"detail":"Authentication credentials were not provided."}
What I've tried so far:
Editing http.conf by sshing into my server and enabling WSGIPathAuthorization. (saw a similar post here and tried the solution)
What could be causing this behavior? My local machine and my deployed code are identical, leading me to believe that this has something to do with server-side configuration.
All help is appreciated. Thanks!

You mentioned ElasticBeanstalk.
You can add this to your container commands which will be executed during deployment.
01_wsgipass:
command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'

Simply restarting Apache after enabling WSGPPathAuthorization fixed my error. For those of you who encounter something similar, here's what I did:
SSH into the server
Navigate to where your http.conf file is stored (in Apache, this is usually
etc/httpd/http.conf)
Edit http.conf, adding WSGIPathAuthorization On.
Restart Apache by running sudo service httpd restart.

This problem usually occurs when you do configure wsgi with apache on EC2 instance.
Bascially its the problem in apache configuration,
it has nothing to do with AWS EC2.
As apache bydefault do not process Authorization headers, so in order to make that happen we need to configure its files.
For ubuntu
cd /etc/apache2/apache2.conf
paste the following line
WSGIPassAuthorization On

Related

Server Error (500) Django App on AWS server

Good day,
i have currently my django project running on an aws server. I have used Nginx and configured it all. The application is running, but when i try to login via the login page i have created or try to login via the admin panel it gives me a Server Error (500). I have my DEBUG=False and added my server dns to ALLOWED_HOSTS. As for the Database. I have got my SQL Database running on an Azure server and used environment variables (that i have permanently set in my ubuntu terminal) to get my password and username.
I have also tried to set DEBUG to False and trying to figure out the issue when running python manage.py runserver so i could experiment with it on my localhost, but no luck. I cant access 127.0.0.1 eventhough i have added it to my Allowed hosts.
How could i see what the error is? Thank you in advance
Ok, so fixed it!
After each change, you simply run the command sudo supervisorctl reload in your powershell after you ssh'ed into your aws ec2 server.
As for seeing what the error is, simply set DEBUG=True

Not able to deploy Django app on AWS Lightsail using Apache server based on provided tutorial

I followed the tutorial (https://aws.amazon.com/getting-started/hands-on/deploy-python-application/) on deploying Django website in AWS Lightsail. When I use the
python3 manage.py runserver 0.0.0.0:8000
to deploy the website then it works perfectly and I can access the website at http://AWS.INSTANCE.PUBLIC.IP.ADDRESS:8000
However, if I follow the Host the application using Apache part of the same tutorial, I am getting the following error when I try to access http://AWS.INSTANCE.PUBLIC.IP.ADDRESS:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at you#example.com 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.
How to successfully deploy the Django website/app using Apache on AWS Lightsail instance?
I was able to run Django on lightsail by following the tutorial.
Make sure all paths in bitnami.conf file is correctly configured. Also, you need to retain the below part.
# Let Apache know we're behind a SSL reverse proxy
SetEnvIf X-Forwarded-Proto https HTTPS=on
This is the part where the tutorial asks to delete but don't delete this part. Below this part, should start.
If you were able to put up the correct paths, you should be able to run Django application on LightSail.
However, there is a bigger problem later on when you try to get HTTPS on lightsail instance;;;

Django's development server on Ubuntu not accessible via browser, only via -curl

I am trying to set up a Django website on an Ubuntu server hosted on DigitalOcean.
After following the step-by-step DigitalOcean tutorial here: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
I remain stuck as I cannot seem to access Django's development server launched on 0.0.0:8000 with the browser of my local machine. However, I do have a response using -curl from the server's bash terminal. So it seems it can only be accessed from the server itself. Django does not return any error while launching the development server. It lists successful connections (code 200) every time I access it via -curl, but does not show anything when I try to access it via my external browser, as if it is actually not being acecssed.
What I did:
followed this tutorial step-by-step until the launch of Django's development server,
disabled Ubuntu's firewall and no DO firewall is used
added '*' in ALLOWED_HOSTS in settings.py
Any ideas? Thank you very much!

404 not found after deploying laravel 5.3 into AWS EC2 server

I deployed (actually cloned from git my site, previously developed on local server) into AWS EC2 instance. I did the necessary things like composer updating, .env file etc. But still it is showing 404 error when I try to visit my site --
{my-public-ip}/{my-site}/public/
what am I missing here?
I ran sudo a2enmod rewrite and for some unknown reason, it worked. Strange! No idea what or how this happened

Unable to setup Django in production on EC2 instance running Ubuntu 14.04

I have set up an EC2 instance with Ubuntu and able to login via ssh.
Now I have installed Apache, MySQL (worked fine) and Django also tried to configure it to run with apache. I have tried doing so with mod-wsgi but it still shows a apache default page instead of django (Congratulation ! It works) page. Can someone please provide me instructions for how to setup all this after login into EC2 via SSH.
Here is a tutorial provided by Django.
You need to make sure the apache config file is in /etc/apache2/sites-enabled/ or wherever your apache configuration files rest.
Another silly problem and this might be your issue is whenever I start a new instance of EC2 there is always a config called "000-default" already in the apache sites-enabled. This needs to be DELETED or DISABLED for apache to read from your config instead.
Hopefully this helps!
For a example check the Step 2 of this link. yum + git + pip + python requirements