Deploying Django: connecting domain and django folder on Apache

I’m deploying Django on an Apache Server with uwsgi from a venv. On my server I have a folder “fh” containing “fh_venv” and “fh_website”. The latter contains the actual project. When I go to myuser.myhoster.tld/fh_website, the site is running just fine. Now I bought a domain example.com and I want example.com to display the site.
On my webserver I created a directory root for example.com and in that folder I put a .htaccess with this content:

RewriteBase /

RewriteRule / https://myuser.myhoster.tld/fh_website

It produces the following error in the apache log:
“[Mon May 24 18:47:35 2021] [error] [pid 24361] mod_autoindex.c(2329): [client 2001:16b8::] AH01276: Cannot serve directory /var/www/virtual/myuser/www.example.com/: No matching DirectoryIndex (index.html,index.htm,index.html.var,index.php,index.cgi,index.sh,nocontent.html) found, and server-generated directory index forbidden by Options directive”
So Apache expects a folder with an index file, but I want it to expect a script. I went through the apache documentation and found ScriptAlias. However that command is not allowed on my hoster.

Any suggestions are welcome.

The basic docs for getting started are at How to use Django with Apache and mod_wsgi | Django documentation | Django

Have you confirmed your hosting service supports Django as a service on that host? (I have worked with hosting services that don’t allow it.)

When you’re serving a Django project through apache, you’re not serving files in the traditional sense. You’re telling apache that references to a URL are to be forwarded to your uwsgi handler.

There’s no need for there to be a direct relationship between the domain name and the directory structure.- your Apache directives identify the domain name being referenced and the destination for that request.

I’ve already read through that page, however I’m deploying with uwsgi in Emperor Mode, not with mod_wsgi. Django is definetly allowed and my django project is working fine from a subfolder on my hoster, with static and media files being delivered just fine. I just want the project to run from a domain now.

What do you mean by “is working fine”? How are you accessing it? Are you accessing the uwsgi process directly by IP address and port? Or are you accessing it through apache already configured to use uwsgi?

The reason the prior questions are important is that the answer depends upon how you’re configuring uwsgi and how you want apache to communicate through it. Since uwsgi is actually handling the Django requests, apache in this mode is functioning solely as a proxy. You’ll probably be configuring either mod_proxy_http or mod_proxy_uwsgi to have apache forward those requests to uwsgi.
(This is separate from setting up apache to serve the static files, which should be collected to a location in your webroot with a separate directory entry.)

In my uwsgi configuration, I’m adressing port 8030 for this project. I had this running in a subfolder on the standard adress that the hoster provides. Something like username.uber.space/subfolder/. There is a tool to create these mappings. I wasn’t aware that this tool could be used to map on external domains.

When setting up Apache, your configuration file for your server includes sections that will look like this (taken from Name-based Virtual Host Support - Apache HTTP Server Version 2.4):

<VirtualHost *:80>
    # This first-listed virtual host is also the default for *:80
    ServerName www.example.com
    ServerAlias example.com 
    DocumentRoot "/www/domain"
</VirtualHost>

<VirtualHost *:80>
    ServerName other.example.com
    DocumentRoot "/www/otherdomain"
</VirtualHost>

But since you’re using apache as a proxy, and not for serving files, you’ll have your proxy directives instead of DocumentRoot.