Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6025

403 Forbidden Error for HTTPS Access to Uploaded Files in Nginx on EC2

$
0
0

I'm running an EC2 instance with Nginx configured to serve static files from a specific directory. When I access the files via HTTP on port 4000, everything works fine. However, when I try to access the same files over HTTPS, I receive a 403 Forbidden error.

Here's what I've done so far:

  1. Nginx Configuration

    server {    server_name server.avandraapp.com;    root /home/ubuntu/actions-runner-backendserver/_work/tripai-backend/tripai-backend/public;    location / {            try_files $uri $uri/ =404;    }    # Add Content-Security-Policy header    add_header 'Access-Control-Allow-Origin''*';    add_header 'Access-Control-Allow-Methods''GET, POST, OPTIONS';    add_header 'Access-Control-Allow-Headers''Origin, Content-Type, Accept, Authorization';    location /uploads/ {            alias /home/ubuntu/actions-runner-backendserver/_work/tripai-backend/tripai-backend/public/uploads;            autoindex on;            allow all;    }    location /api {        rewrite ^\/api\/(.*)$  /api/$1 break;        proxy_pass http://localhost:4000;        proxy_set_header Host $host;        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    }    listen [::]:443 ssl ipv6only=on; # managed by Certbot    listen 443 ssl; # managed by Certbot    ssl_certificate /etc/letsencrypt/live/server.avandraapp.com/fullchain.pem; # managed by Certbot    ssl_certificate_key /etc/letsencrypt/live/server.avandraapp.com/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 = server.avandraapp.com) {       return 301 https://$host$request_uri;   } # managed by Certbot        listen 80 default_server;        listen [::]:80 default_server;        server_name server.avandraapp.com;        return 404; # managed by Certbot}
  1. File and Directory Permissions
sudo chown -R www-data:www-data /home/ubuntu/actions-runner-backendserver/_work/tripai-backend/tripai-backend/public/uploadssudo chmod -R 755 /home/ubuntu/actions-runner-backendserver/_work/tripai-backend/tripai-backend/public/uploadssudo chmod +x /home/ubuntu/actions-runner-backendserver/_worksudo chmod +x /home/ubuntu/actions-runner-backendserver/_work/tripai-backendsudo chmod +x /home/ubuntu/actions-runner-backendserver/_work/tripai-backend/tripai-backendsudo chmod +x /home/ubuntu/actions-runner-backendserver/_work/tripai-backend/tripai-backend/publicsudo chmod +x /home/ubuntu/actions-runner-backendserver/_work/tripai-backend/tripai-backend/public/uploads
  1. Error Logs:
[error] 53511#53511: *3 open() "/home/ubuntu/actions-runner-backendserver/_work/tripai-backend/tripai-backend/public/uploads/destination/image/image-1714166321743-183488313.jpg" failed (13: Permission denied), client: 94.187.19.52, server: server.avandraapp.com, request: "GET /uploads/destination/image/image-1714166321743-183488313.jpg HTTP/1.1", host: "ec2-13-53-111-155.eu-north-1.compute.amazonaws.com"
  1. Security Groups:Ports 80 and 443 are open in the EC2 instance's security group to allow HTTP and HTTPS traffic.

I'm at a loss on how to proceed to fix the 403 Forbidden error for HTTPS access. Any guidance or suggestions would be greatly appreciated!


Viewing all articles
Browse latest Browse all 6025

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>