I am trying to deploy a site on to a linux server following Corey Schafer's guide for Flask.
My site is working, but nginx is unable to read/access/find the static folder and the files within.
I initially removed the default sites-enabled and created a custom one:
sudo rm /etc/nginx/sites-enabled/default
Then:
sudo nano /etc/nginx/sites-enabled/flaskblog
This is what I input into that file:
server {
listen 80;
server_name DOMAIN_IP;
location /static {
alias /Users/myname/VScode/Flask_Blog/flaskblog/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
}
But all static pages return 404
If I check the error log of nginx I see:
2022/06/03 06:09:42 [error] 71064#71064: *1 open() "/Users/myname/VScode/Flask_Blog/flaskblog/static/main.css" failed (2: No such file or directory), client: 217.146.83.247, server: IP, request: "GET /static/main.css HTTP/1.1", host: "IP", referrer: "http://IP/"
2022/06/03 06:09:42 [error] 71064#71064: *1 open() "/Users/myname/VScode/Flask_Blog/flaskblog/static/profile_pics/271fcf0ffe2a92aa.jpg" failed (2: No such file or directory), client: 217.146.83.247, server: IP, request: "GET /static/profile_pics/271fcf0ffe2a92aa.jpg HTTP/1.1", host: "IP", referrer: "http://IP/"
2022/06/03 06:09:42 [error] 71064#71064: *4 open() "/Users/myname/VScode/Flask_Blog/flaskblog/static/profile_pics/default.jpg" failed (2: No such file or directory), client: 217.146.83.247, server: IP, request: "GET /static/profile_pics/default.jpg HTTP/1.1", host: "IP", referrer: "http://IP/"
2022/06/03 06:09:45 [error] 71064#71064: *4 open() "/Users/myname/VScode/Flask_Blog/flaskblog/static/main.css" failed (2: No such file or directory), client: 217.146.83.247, server: IP, request: "GET /static/main.css HTTP/1.1", host: "IP", referrer: "http://IP/home"
So I can see that nginx is going to the correct location, so I don't understand why it is saying "No such file or directory"
I have tried both
location /static {
alias /Users/myname/VScode/Flask_Blog/flaskblog/static;
}
and
location /static {
root /Users/myname/VScode/Flask_Blog/flaskblog;
}
And both produce the same error and same location.
I have also cd'd down and then done ls
at each point to check that everything is in the right place and everything seems in order
(venv) charles@flask-server:~/Flask_Blog$ ls
flaskblog __pycache__ requirements.txt run.py venv
(venv) charles@flask-server:~/Flask_Blog$ cd flaskblog
(venv) charles@flask-server:~/Flask_Blog/flaskblog$ ls
config.py errors __init__.py main models.py posts __pycache__ site.db static templates users
(venv) charles@flask-server:~/Flask_Blog/flaskblog$ cd static
(venv) charles@flask-server:~/Flask_Blog/flaskblog/static$ ls
main.css profile_pics
(venv) charles@flask-server:~/Flask_Blog/flaskblog/static$ cd main.css
-bash: cd: main.css: Not a directory
(venv) charles@flask-server:~/Flask_Blog/flaskblog/static$ cd profile_pics
(venv) charles@flask-server:~/Flask_Blog/flaskblog/static/profile_pics$ ls
And if I go to "/Users/myname/VScode/Flask_Blog/flaskblog/static" on my personal machine it goes to the correct place.
Thank you for any help.