I'm trying to configure nginx so that it can serve both React and Django. Here is my configuration:
server { listen 80; server_name 182.20.4.110 mydomain.io; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/ubuntu/myproj_app/static/; } location / { alias /home/ubuntu/myproj_app/frontend/build/; } location /apidoc { include proxy_params; proxy_pass http://unix:/run/gunicorn.sock; }
}
https://gist.github.com/axilaris/2329d3ff73034b51483366772c7cef9c
However, I keep getting
403 Forbidden
And based on the nginx error logs, it keeps getting permission denied in the React build directory
sudo tail -f /var/log/nginx/error.log2024/04/01 12:23:57 [error] 3616#3616: *68 "/home/ubuntu/myproj_app/frontend/build/index.html" is forbidden (13: Permission denied), client: 172.20.4.193, server: 182.20.4.110, request: "GET / HTTP/1.1", host: "182.20.4.110"2024/04/01 12:23:58 [error] 3616#3616: *69 "/home/ubuntu/myproj_app/frontend/build/index.html" is forbidden (13: Permission denied), client: 172.20.1.172, server: 182.20.4.110, request: "GET / HTTP/1.1", host: "182.20.4.110"2024/04/01 12:24:21 [error] 3616#3616: *67 "/home/ubuntu/myproj_app/frontend/build/index.html" is forbidden (13: Permission denied), client: 172.20.1.172, server: 182.20.4.110, request: "GET / HTTP/1.1", host: "mydomain.io"2024/04/01 12:24:27 [error] 3616#3616: *70 "/home/ubuntu/myproj_app/frontend/build/index.html" is forbidden (13: Permission denied), client: 172.20.4.193, server: 182.20.4.110, request: "GET / HTTP/1.1", host: "182.20.4.110"2024/04/01 12:24:28 [error] 3616#3616: *71 "/home/ubuntu/myproj_app/frontend/build/index.html" is forbidden (13: Permission denied), client: 172.20.1.172, server: 182.20.4.110, request: "GET / HTTP/1.1", host: "182.20.4.110"2024/04/01 12:24:30 [error] 3616#3616: *67 "/home/ubuntu/myproj_app/frontend/build/index.html" is forbidden (13: Permission denied), client: 172.20.1.172, server: 182.20.4.110, request: "GET / HTTP/1.1", host: "mydomain.io"
I tried to change owner to nginx user www-data but still gets permission denied
ubuntu@ip-182-20-4-110:~$ ls -ld /home/ubuntu/myproj_app/frontend/build/drwxr-xr-x 3 www-data www-data 4096 Apr 1 09:47 /home/ubuntu/myproj_app/frontend/build/ubuntu@ip-182-20-4-110:~$ sudo -u www-data ls /home/ubuntu/myproj_app/frontend/build/ls: cannot access '/home/ubuntu/myproj_app/frontend/build/': Permission denied
How can I solve this. I cant serve my React pages with nginx on ubuntu 22.04. And this is on EC2 on AWS setup by someone which I have no control. Could AWS have any settings in the policy to prevent access ?