/home/~USER/public_html/django.fcgi/ was not found on this server - django

This is making me crazy. My .htaccess is
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]
And my django.fcgi looks ok
#!/usr/bin/python
import os, sys
PROJECT_PATH = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'/home/USER/django-example-project/example_website'))
venv = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'/home/USER/django-example-project/venv/bin/activate_this.py'))
execfile(venv, dict(__file__=venv))
sys.path.insert(0, "{0}/../example_website".format(PROJECT_PATH))
os.environ['DJANGO_SETTINGS_MODULE'] = "example_website.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
When I put in the browser http://localhost/~USER it gives me error
The requested URL /home/~USER/public_html/django.fcgi/ was not found on this server.
Why I am getting this error.
Both my .htacces and django.fcgi are in public_html directory. I have tried many things but it always shows this :(

Related

How to set up Django for Fastpanel

I used .htaccess
Options +ExecCGI
AddHandler wsgi-script .py
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /wsgi.py/$1 [QSA,PT,L]
for HestiaCP and wsgi.py
import os
import sys
sys.path.append('PATH_TO_PROJECT')
sys.path.append('PATH_TO_PACKAGES_PYTHON')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project_name.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
and it worked but doesn't work in Fastpanel. How to be?
apt install libapache2-mod-wsgi-py3
and read this: https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/modwsgi/

URL configuration issue with Django app using Bluehost

I'm in the process of deploying my Django app to a production server using Bluehost but keep seeing my site's 404 page. The issue seems to be my URL configuration. When I type http://www.example.com/ into my browser I receive the following :
Request URL: http://www.example.com/public_html/
^main/
^admin/
^accounts/
^media/(?P<path>.*)$
etc..
The current URL, public_html/, didn't match any of these
public_html/ is automatically added to the end of my URL I would like to eliminate the public_html/ entirely so my URL pattern will work as expected. For example
Request URL: http://www.example.com/
Which would then redirect to
Request URL: http://www.example.com/main/
How would I go about changing the default from http://www.example.com/public_html/ to http://www.example.com/ ?
My fcgi file:
AddHandler fcgid-script .fcgi
RewriteEngine on
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(adminmedia/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(cgi-bin/mysite.fcgi)
RewriteRule ^(.*)$ cgi-bin/mysite.fcgi/$1 [L]
My .htaccess file:
#!/home/username/python/bin/python
import sys, os
sys.path.insert(0, "/home/username/python")
sys.path.insert(13, "/home/username/MySite")
os.environ['DJANGO_SETTINGS_MODULE'] = 'MySite.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
Is there a possibility this could be an issue with where my files are located on my server? If anyone has experienced this kind of issue before I would greatly appreciate some advice. Thanks!
You have to define following url in your urls.py,
url(r'^$', 'views.home', name='home')
url(r'^main/$', 'views.main', name='main')
then in views.py
def home(request):
return HttpResponseRedirect('/main/')
def main(request):
#some code here.

Django Response Delay for every request

currently, I move my Django application on a production server. The problem is that each request to the server is slower by 1 second, then locallhost. (I don't mean static files. For testing I made ​​a simple VIEW, that not access the database and not contain python code only return string) I did get this values(delay 1 second) ​​of Chrome / Network/ Property - request - Waiting. Property Sending/receiving is normal (cca 1-10ms)
My .htaccess:
AuthType none
Satisfy Any
Allow from All
AddHandler fast-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /mysite.cgi/$1 [QSA,L]
My mysite.cgi:
#!/usr/bin/python
# -*- coding: utf8 -*-
import sys, os
# to suppress browser output, you should explicitly say so.
import cgitb
cgitb.enable(display=True)
# Add a custom Python path.
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ.setdefault("DJANGO_SETTINGS_MODULE","Web.settings")
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="False")
I'm not server admin, so haven´t permission for setting Apache etc.
It is possible that the application not uses FastCGI but CGI? Or something like that?
Thanks
Problem solved by server admin, the server has not installed mod_fcgid.

Django FastCGI and 500 Internal Server Error

I tried to install Django with FastCGI but without success!. It gives me a 500 Error, but if I execute my ./dispatch.fcgi on shell it gives me the "it works!" HTML page of Django.
Here is my url http://mydjango.webmashing.com
and my dispatch.fcgi file is
#!/usr/bin/python
import sys, os
sys.path.insert(0, "/home/webmashi/.local/lib/python")
os.chdir("/home/webmashi/.local/lib/python/myproject")
os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
.htaccess file:
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]
I update my python version from 2.4 to 2.6 and it's worked :)

FCGI htaccess handler

I'm trying to setup django on a shared hosting provider. I followed the instructions on http://helpdesk.bluehost.com/index.php/kb/article/000531
and almost have it working.
The problem I'm facing now is that the traffic is properly routed throught the fcgi file, but the file itself shows up as plain text in the browser. If I run ./mysite.fcgi in the ssh shell, I do get the default django welcome page.
my .htaccess is:
AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]
and mysite.fcgi:
#!/usr/bin/python2.6
import sys, os
os.environ['DJANGO_SETTINGS_MODULE'] = "icm.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
thanks.
Try removing AddHandler, or changing it to:
AddHandler fcgid-script .fcgi