| SYSTEM INFORMATION||
|------------------------------|-------------------------------|
Operating system Ubuntu Linux | 24.04.1
Webmin version | 2.202
Virtualmin version | 7.30.4
Apache Webserver | 2.4.58
I am working on a Python-based Flask API, and all its files are located on a subserver/subdomain. When I try to access the API through the subdomain(URL), it returns a 403 error stating, “Forbidden: You don’t have permission to access this resource.” However, when I access the same API using the local or public IP, it opens and works perfectly.
Presumably you’ve got an application server serving the Python, and presumably that’s on a port, and when you say it “works using the local or public IP” you mean you’re also using the port?
If so, you need to proxy to your application. You may be able to use Proxy Paths in the Virtualmin GUI, or you may need to do something more complicated (depending on expectations of your application wrt URLs and such).
You should not put Python applications in public_html.
Users have no business in the Python, and Apache cannot do anything useful for Python files.
Only static files (HTML, CSS, images, etc.) belong in public_html. Python isn’t like PHP, it doesn’t live in the document root, it’s got its own web server which should be serving the application on a port on localhost (or, better, a socket), and the web server should proxy to it.
I saw that, and already answered. That’s not where Python files belong. Python runs under an application server, not Apache. So, they don’t need to be in the document root, and since they don’t need to be in the document root, they should not be in the document root (for safety, if you make a mistake in your configuration files, your files could be or become visible to users).
The reason it’s not working is not related to where the files are. The reason it’s not working is because you’re expecting Apache to run Python, and that’s not how it works. You need an application server, and presumably you have one running since you said you can access it on the IP (with a port, I guess). You need to proxy to that application server.
I’m also telling you to not do something potentially dangerous. Get your files out of public_html. They don’t belong there.
I’m repeating myself, though. Please just re-read what I’ve already written. I have told you what you need to do, multiple times.
sir I have provided above with the files and folder structure newly set, but the document route in the apache config file is pointing towards the public_html, in my limited knowledge here app.py is the main entry point for your Flask application
As I indicated above changing an app from Nginx to Apache is not a simple task - likewise Apache to Nginx. Apache makes extensive use of .htaccess files Nginx does not. And anyway as already pointed out this is a Python app so should be proxy to localhost.
I stopped using Apache years ago. I also have only very little experience with Python.
As for time to get a response - please be aware that this is a forum and is dependant on the attention of its membership across the world and their various time zones - people sleep and their attention span is also limited to free time. Technical Support is limited (see Pro membership)
No! That’s even worse. That is still a document root (where Python files do not belong), and it isn’t where homes live in a Virtualmin environment. You would ideally put applications that run under an application server in a directory in the home of the domain owner user (e.g. /home/domain-name/my-app), not in a document root. Apache does not run Python applications, so it doesn’t make sense to put those applications into the Apache document root. (It may be that your app also also uses static files, like HTML, images, media, etc., which you want the web server to serve, in which case you can/should put those files into the document root.)
But, the location is still not the reason your application isn’t working. The problem continues to be you need to proxy to applications that have application servers. You need a ProxyPass directive and maybe a ProxyPassReverse. Don’t forget to exclude .well-known so you can continue to get Let’s Encrypt certificates.
I can’t believe I have to link you to the damned documentation for the framework and language you chose yourself. Is this really how helpless you are? OK, fine, here it is: