Been following a tutorial on udemy for python, and atm im suppose to get a django app deployed.
Since I already had a vps, I didnt go with the solution on the tutorial using google cloud, so tried to configure the app on my vps, which is also running plesk.
Followed the tutorial at https://www.plesk.com/blog/tag/django-plesk/ to the letter the best I could, but keep getting the 403 error.
httpdocs
-djangoProject
---djangoProject
------asgi.py
------__init__.py
------settings.py
------urls.py
------wsgi.py
---manage.py
-passenger_wsgi.py
-python-app-venv
-tmp
passenger_wsgi.py:
import sys, os
ApplicationDirectory = 'djangoProject'
ApplicationName = 'djangoProject'
VirtualEnvDirectory = 'python-app-venv'
VirtualEnv = os.path.join(os.getcwd(), VirtualEnvDirectory, 'bin', 'python')
if sys.executable != VirtualEnv: os.execl(VirtualEnv, VirtualEnv, *sys.argv)
sys.path.insert(0, os.path.join(os.getcwd(), ApplicationDirectory))
sys.path.insert(0, os.path.join(os.getcwd(), ApplicationDirectory, ApplicationName))
sys.path.insert(0, os.path.join(os.getcwd(), VirtualEnvDirectory, 'bin'))
os.chdir(os.path.join(os.getcwd(), ApplicationDirectory))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', ApplicationName + '.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
passenger is enabled in
"Tools & Settngs > Apache Web Server"
in "Websites & Domains > Domain > Hosting & DNS > Apache & nginx settings" I’ve got:
"Additional directives for HTTP" and "Additional directives for HTTPS" both with:
PassengerEnabled On
PassengerAppType wsgi
PassengerStartupFile passenger_wsgi.py
and nginx proxy mode marked
"Reverse Proxy Server (nginx)" is also running
No idea what else I can give to aid in getting a solution, so if you’re willing to assist and need more info please let me know.
Very thankfull in advance
EDIT:
on a previous attempt, deploying a real app on a subdomain, was getting:
[Thu Apr 01 22:52:37.928495 2021] [autoindex:error] [pid 23614:tid
140423896925952] [client xx:xx:xx:xx:0] AH01276: Cannot serve
directory /var/www/vhosts/baya.pt/leve/leve/: No matching
DirectoryIndex
(index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm,index.shtml)
found, and server-generated directory index forbidden by Options
directive
This time I’m getting no errors logged
EDIT2:
@Chris:
Not sure what you mean, find no errors on the log folders (ssh), but on Plesk I get this several times:
2021-04-01 23:40:48 Error 94.61.142.214 403 GET /
HTTP/1.0 https://baya.pt/ Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114
Safari/537.36 2.52 K Apache SSL/TLS access 2021-04-01
23:40:48 Error 94.61.142.214 AH01276: Cannot serve directory
/var/www/vhosts/baya.pt/httpdocs/djangoProject/: No matching
DirectoryIndex
(index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm,index.shtml)
found, and server-generated directory index forbidden by Options
directive, referer: https://baya.pt/ Apache error
EDIT 3:
removing apache directives and adding to nginx directives:
passenger_enabled on;
passenger_app_type wsgi;
passenger_startup_file passenger_wsgi.py;
Now gives me a Passenger error page, log as follows:
[ N 2021-04-01 23:50:59.1819 908/T9 age/Cor/CoreMain.cpp:671 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ N 2021-04-01 23:50:59.1819 908/T1 age/Cor/CoreMain.cpp:1246 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ N 2021-04-01 23:50:59.1820 908/Tb Ser/Server.h:902 ]: [ApiServer] Freed 0 spare client objects
[ N 2021-04-01 23:50:59.1820 908/Tb Ser/Server.h:558 ]: [ApiServer] Shutdown finished
[ N 2021-04-01 23:50:59.1820 908/T9 Ser/Server.h:902 ]: [ServerThr.1] Freed 0 spare client objects
[ N 2021-04-01 23:50:59.1820 908/T9 Ser/Server.h:558 ]: [ServerThr.1] Shutdown finished
[ N 2021-04-01 23:50:59.2765 30199/T1 age/Wat/WatchdogMain.cpp:1373 ]: Starting Passenger watchdog...
[ N 2021-04-01 23:50:59.2871 908/T1 age/Cor/CoreMain.cpp:1325 ]: Passenger core shutdown finished
[ N 2021-04-01 23:50:59.3329 30209/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core...
[ N 2021-04-01 23:50:59.3330 30209/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2021-04-01 23:50:59.3472 30209/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 30209
[ N 2021-04-01 23:51:01.4339 30209/T7 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours)
App 31762 output: Error: Directory '/var/www/vhosts/baya.pt' is inaccessible because of a filesystem permission error.
[ E 2021-04-01 23:51:02.9127 30209/Tc age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/vhosts/baya.pt/httpdocs: Directory '/var/www/vhosts/baya.pt' is inaccessible because of a filesystem permission error.
2
Answers
Think I've got it:
Added directives to nginx, removed proxy mode, and chown passenger_wsgi.py to nginx
at least Im getting a django page now =)
I spent a few days implementing this process and finally found what needed to be modified. So, I’m sharing my findings and hope it will help you as well.
After completing the process step by step, I was getting the error:
No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm,index.shtml) found, and server-generated directory index forbidden by Options directive
So, I unchecked the proxy mode to switch to nginx instead of apache. This time the Phusion Passenger was loading the page but it was saying that something was wrong. It didn’t tell me what was wrong. So I did the following:
cd /etc/nginx/conf.d/
touch directives.conf
vi /etc/nginx/conf.d/directives.conf
a text editor opened and I typed:
passenger_app_env development;
This time when I tried to open my website, passenger showed me the error details from which I found what was wrong.
In step 6, instead of using the command $ vi ~/httpdocs/passenger_wsgi.py, just create the file on your computer, copy the content in it, save it on your local machine and then manually upload it on the server. Don’t use the command line!!!
That’s it. now my Django website is up and running.