0

I am trying to make with this

csv_file = 'static/result.csv'
with open(csv_file,'a') as f:

It works on python manage runserver

However on nginx_unit there comes error like this,

PermissionError: [Errno 13] Permission denied: 'result.csv'

static folder is 777 already

lrwxrwxrwx 1 ubuntu ubuntu 38 Dec 28 19:32 static

Why this permission error happens??

in my settings.py

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATIC_ROOT = os.path.join(config("PROJ_PATH"), 'staticroot')

my nginx_unit setting is here below

{
    "listeners": {
        "*:8010": {
            "pass": "applications/myapp",
        }
    },

    "applications": {
        "myapp": {
            "type": "python 3.8",
            "module": "myapp.wsgi",
            "home": "/home/ubuntu/anaconda3/envs/myapp/",
            "path": "/var/www/html/myapp/current"
        }
    }
}
whitebear
  • 11,200
  • 24
  • 114
  • 237
  • Firstly, is nginx setup to serve your static files directly? (This would be the usual way to do things) - if so in the nginx configuration, what is the alias for /static set to? Secondly, what are the unix permissions for that directory - and its contents? The error message you are seeing suggests that nginx can see that the file exists (i.e. it has rx permissions on the static directory, but not r permissions on the file. This could happen if the user account that ran manage.py collectstatic is not setting the static files to be group or world readable. – Gavin Burnell Dec 28 '21 at 10:58
  • I ma using `nginx-unit` not `nginx` I added the setting to the article. and my unix permission is 777 `lrwxrwxrwx 1 ubuntu ubuntu 38 Dec 28 19:32 static` I try to make another directory and make permission 777 but in vain. Maybe unix permission is not used for nginx-unit???? – whitebear Dec 28 '21 at 11:15
  • Yes but what are the permissions on the results.csv file? Your nginix_unit server needs to have rx on the static files directory and r on the results.csv file.... – Gavin Burnell Dec 28 '21 at 13:55
  • OK, but in this case there is no results.csv I use flg `a` for `with open(csv_file,'a') as f:` In my understanding, if there is no file, the file should be created. – whitebear Jan 02 '22 at 13:05

0 Answers0