I am trying to run a flask application on an Ec2 ubuntu, instance, I am using nginx and gunicorn for the same. The problem that I am facing is that on http I can access my urls but on https only the default i.e “/” is working
Example : http://nearhire.app/get_skillsets
– returns the proper values but https://get_skillsets/get_skillsets
returns a 404 error
The same urls when ran on port 5000 works perfectly.
So http://15.207.16.151:5000/get_skillsets works
My gunicorn set is :
[Unit]
Description=Gunicorn instance for Job Application
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/JobProject
ExecStart=/home/ubuntu/.local/bin/gunicorn --bind 0.0.0.0:5000 --workers=4 --timeout=60 main:app
Restart=always
[Install]
WantedBy=multi-user.target
and my nginx structure (/etc/nginx/sites-available/default) is :
upstream jobapplication {
server 127.0.0.1:5000;
}
server {
listen 80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://jobapplication;
}
}
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name www.nearhire.app nearhire.app; # managed by Certbot
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://jobapplication;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
include proxy_params;
try_files $uri $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/nearhire.app/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/nearhire.app/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.nearhire.app) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = nearhire.app) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name nearhire.app;
return 404; # managed by Certbot
}
PS : all the apis (Except the default one ‘/’) return jsonified values, they do not load any page whatsoever (The reason I am using nginx is for letenscrypt ssl)
Do let me know if any additional information is required