Trouble with HTTPD on Apache

I’m trying to run a simple Fastapi App on an Apache Server and I’m getting an error message when I try restarting the server after finishing the app.conf file inside the /etc/httpd/conf.d directory. Evidently the error is on line 2 of this file:

<VirtualHost *:80>
ServerName http://–…56.1…20 # Replace with your domain name
Alias / /var/www/app.wsgi

<Directory /var/www/app>
Require all granted

ErrorLog /var/log/httpd/app-error.log
LogLevel warn

Can you see what my issue is? I’m getting his error message:

Syntax error on line 2. ServerName takes one argument

Thanks in advance.

You can’t use “http://” there, it has to be the format of (without the quotes) “www.somename.com”. I do not know if that will work with your IP address, but if it does, then it’s just the address, “123.123.123.123”

1 Like

It seems that you’ve made a couple of mistakes,
First as Albert stated you cannot use “–…56.1…20” as a domain name, and cannot state the protocol (i.e. HTTP) inside the ServerName option the right way to do this would be:

ServerName example.com

Furthermore, the Alias option is not meant to store a path (I’m not sure what “/ /var/www/app.wsgi” is supposed to represent) but an alternative domain, e.g. site.example.com

Alias web.example.com

I hope I was able to assist!

2 Likes

Thank you both albert.mccann and noam-alum. I really appreciate it.

This is my first experience using an Apache server and I need to be patient while I learn.

I’m trying to put a Python program on an Almalinux 9 running on a Linode. I may have gotten way over my head to attempt to run a FastAPI in Apache, so now I’m going to see if I can get Flask up and running.

If either of you or anyone else has any tips or ideas for me I am appreciative.

Thanks again.

The general use of FastAPI is like so:

ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/

8000 being the port you want to forward from your Python application, note that the use of HTTP or HTTPS in the protocol used while port forwarding should be HTTP for 80 and HTTPS for 443.

This is an example configuration file you can use:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com

    ErrorLog /home/USER/logs/error.log
    CustomLog /home/USER/logs/access.log combined    

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/
</VirtualHost>

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com

    ErrorLog /home/USER/logs/error.log
    CustomLog /home/USER/logs/access.log combined    

    ProxyPreserveHost On
    ProxyPass / https://127.0.0.1:8000/
    ProxyPassReverse / https://127.0.0.1:8000/
</VirtualHost>

Hope this helps.

Thanks.

I tried this with Fastapi and I couldn’t get it to work. The browser wouldn’t show anything when I tried and retried a bunch of different things.

Have you changed the port used to the port on your python application?

Like I stated earlier

ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/

8000 being the port you want to forward from your Python application

So you have to swap 8000 with the port you’ve stated in your python application.

Further more if you are using a non registered (nore configured) domain and your trying to access it through a browser it obviously won’t work, you’d have to use a hosts file manipulation to view it properly.

If you are trying to access the website trough the servers public ip address, while it might work in some cases (depending on the configuration of the Apache web server) in most of them you should get the Apache AlmaLinux default page.
e.g.
image

I think you went a bit over your head with this project, you might want to make a simpler setup work before port forwarding, you can definitely try to use the

DocumentRoot

directive to request a simple html page from a directory in the server to ensure connectivity with Apache and clients (i.e. you).

Hi Noam,

Yes. I did change the port as you suggested. That didn’t work. I have a very small test application that runs great on my local machine.

I have to use Uvicorn to run the application. It runs it on AlmaLinux without error. However, I am unable to get it to run in my browser which it should if I have things configured properly which I obviously don’t. When I start Uvicorn which is acting as my server it says it’s running on http://127.0.0.1:8000/ Since I changed the port as you suggested I do earlier I would expect to be able to run it in my browser but I cannot.

As far as me being able to get a regular website up and running on Apache through my browser I can do that. It replaces the AlmaLinux Test Page which you have shown. I am using the /var/www/html folder for that.

I have been trying to switch the port in another folder: /etc/httpd/conf.d Evidently this is where you have to put the file you showed me how to prepare. I have prepared that file and named it app.conf. I named it that because my project lives in /var/www/app.

Now /etc/httpd/conf.d contains a few other files, one of which is welcome.conf This file has the ability to show the AlmaLinux Test File page through the browser.

So as I said, I tried a bunch of different things to get the fastapi running into my browser but have only been successful at getting a simple web page up.

Thanks again for the help.

From what you wrote here there is no reference on how you are trying to access the website as of now (That is from the server) but I can recall you are trying to access it through 127.0.0.1, that is a loopback address and it won’t work.
The application is telling you that it’s running on “http://127.0.0.1:8000” meaning it is using an internal port (8000) which we’ve set in the configuration file to forward to 80 or 443, meaning you do not access the application with a port (e.g. 8000) you access it trough ports 80 or 443 depending on the protocol you’re using, so to access the website the right way would be using the domain specified in the configuration file.

As I’ve stated earlier:

Further more if you are using a non registered (nore configured) domain and your trying to access it through a browser it obviously won’t work, you’d have to use a hosts file manipulation to view it properly.

Please make sure to follow the instructions in the link above, if you did everything right you should get either the actual website or an error with a status code of 503 (most properly) which means the Apache configuration is correct but there was an issue with the communication with the application.

It would be easier for me to help you if specify how you are accessing the website, the configuration file you are using, and the output of systemctl status httpd.