I'm running flask on mod_wsgi. my flask app, which is on /var/www/app
receives some file from user and saves it to /var/www/app/tmp
directory. However even after all chmod and chown(thought it was a permission problem), I was unable to reach that tmp directory.
After some debugging I found out that the current working directory of the flask app is /
.
I can change working directory by os.chdir('/var/www/')
, but I'd like to avoid that for security concerns.
here is my apache configuration:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias site.com
ServerAdmin admin@localhost
WSGIDaemonProcess app user=www-data group=www-data processes=1
WSGIScriptAlias / /var/www/app.wsgi
Alias /static /var/www/app/static
<Directory /var/www/app>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</Directory>
<Location "/static">
SetHandler None
</Location>
</VirtualHost>
How can I change working directory of my app from /
to /var/www
?
If installing the Apache module by hand, the file is called 'mod_wsgi.so'. The compiled Apache module can be found in the “. libs” subdirectory. The name of the file should be kept the same when copied into its appropriate location.
The Web Server Gateway Interface (WSGI, pronounced whiskey or WIZ-ghee) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, version 1.0. 1, is specified in Python Enhancement Proposal (PEP) 3333.
Used to indicate to Python when it is initialised where its library files are installed.
The WSGIScriptAlias directive behaves in the same manner as the Alias directive, except that it additionally marks the target directory as containing WSGI scripts, or marks the specific file-path as a script, that should be processed by mod_wsgi's wsgi-script handler.
The documentation for WSGIDaemonProcess says you can use the home=...
stanza:
home=directory
Defines an absolute path of a directory which should be used as the initial current working directory of the daemon processes within the process group. If this option is not defined, in mod_wsgi 1.X the current working directory of the Apache parent process will be inherited by the daemon processes within the process group. Normally the current working directory of the Apache parent process would be the root directory. In mod_wsgi 2.0+ the initial current working directory will be set to be the home directory of the user that the daemon process runs as.
I'm curious, though -- why would using os.chdir
be any more of a security risk in your opinion?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With