Apache troubleshotting in AWS EC2

Okey . I have a problem deploying my django app to ec2 with apache. My project is under /home/ubuntu/byteb0x. The wsgi is inside /home/ubuntu/byteb0x/byteb0x. I used venv and its folder is under /home/ubuntu/byteb0x/venv. After collectstatic my files went to /home/ubuntu/byteb0x/staticfiles as i have setted it in root urls, and media went to /home/ubuntu/byteb0x/media. I use ubuntu 22.04.I have installed apache2 and libapache2-mod-wsgi-py3. Migrations are done, allowed hosts are the ec2 instance ipv4 and future domains that will point. Database is connected to AWS RDS and configuration setted with .env and decouple. The python packages i have installed in the venv are :
asgiref==3.7.2; Django==5.0; django-ckeditor-5==0.2.10; Pillow==10.1.0; psycopg2-binary==2.9.9; python-decouple==3.8; sqlparse==0.4.4; typing_extensions==4.9.0; tzdata==2023.3

Here is my setup and the error.

wsgi.py:

import os, sys

sys.path.append('/home/ubuntu/byteb0x')
sys.path.append('/home/ubuntu/byteb0x/venv/lib/python3.10/site-packages')

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'byteb0x.settings')

application = get_wsgi_application()
`

my byteb0x.conf:

<VirtualHost *:80>
    ServerAdmin bartek.cwb@gmail.com
    ServerName 000.000.000.000 [I have my ec2 instance IP setted here, maybe thats teh issue idk]
    ServerAlias www.byteb0x.com byteb0x.com [future domains that i will point to the Ip]
    DocumentRoot /home/ubuntu/byteb0x
    <Directory /home/ubuntu/byteb0x>
        Require all granted
    </Directory>

    Alias /media /home/ubuntu/byteb0x/media
    Alias /static /home/ubuntu/byteb0x/staticfiles

    <Directory /home/ubuntu/byteb0x/staticfiles>
        Require all granted
    </Directory>

    <Directory /home/ubuntu/byteb0x/media>
    Require all granted
    </Directory>

    <Directory /home/ubuntu/byteb0x/byteb0x>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>


    WSGIDaemonProcess byteb0x python-path=/home/ubuntu/byteb0x python-home=/home/ubuntu/byteb0x/venv
    WSGIApplicationGroup byteb0x
    WSGIScriptAlias / /home/ubuntu/byteb0x/byteb0x/wsgi.py

</VirtualHost>

The error i get in /var/log/apache2/error.log:

[Mon Dec 11 02:56:10.666076 2023] [mpm_event:notice] [pid 18326:tid 140298787428224] AH00492: caught SIGWINCH, shutting down gracefully
[Mon Dec 11 02:56:10.821245 2023] [mpm_event:notice] [pid 18423:tid 140131736803200] AH00489: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Mon Dec 11 02:56:10.821381 2023] [core:notice] [pid 18423:tid 140131736803200] AH00094: Command line: '/usr/sbin/apache2'
[Mon Dec 11 02:57:24.902169 2023] [mpm_event:notice] [pid 18423:tid 140131736803200] AH00492: caught SIGWINCH, shutting down gracefully
[Mon Dec 11 02:57:25.091014 2023] [mpm_event:notice] [pid 18515:tid 140387465521024] AH00489: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Mon Dec 11 02:57:25.091162 2023] [core:notice] [pid 18515:tid 140387465521024] AH00094: Command line: '/usr/sbin/apache2'
[Mon Dec 11 02:59:39.954772 2023] [mpm_event:notice] [pid 18515:tid 140387465521024] AH00492: caught SIGWINCH, shutting down gracefully
[Mon Dec 11 02:59:40.090211 2023] [mpm_event:notice] [pid 18612:tid 140363227170688] AH00489: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Mon Dec 11 02:59:40.090331 2023] [core:notice] [pid 18612:tid 140363227170688] AH00094: Command line: '/usr/sbin/apache2'
[Mon Dec 11 03:05:14.537684 2023] [mpm_event:notice] [pid 18612:tid 140363227170688] AH00492: caught SIGWINCH, shutting down gracefully
[Mon Dec 11 03:05:14.693842 2023] [mpm_event:notice] [pid 18712:tid 139816718133120] AH00489: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Mon Dec 11 03:05:14.693968 2023] [core:notice] [pid 18712:tid 139816718133120] AH00094: Command line: '/usr/sbin/apache2'

Also, when i point to the Ip with my browser, the server rejects the conexion.

I need help. I have been looking to solve this since 23:00 and it is 4:34 right now in Spain. So if u need anything more to help me just ask for it. Thank you all.

How are you running Apache? Are you trying to run it directly from the command-line, or are you using systemd? (Or something else?)

I’m using systemd. I will try to run in directly right now.

Actually, I was more concerned the other way. SIGWINCH is a signal that is (typically) registered for a “WINdow CHange”. Using systemd is much preferred.

Are you using the system-installed systemd file, or one that has been modified?

<opinion><conjecture>
Note: I’ll also point out that this appears to be unrelated to your Django application. It looks like it would be an indication of a configuration issue somewhere else.
</opinion></conjecture>

Also, in addition to looking at your apache error log, check syslog for any apache-related errors.

I’m using system-installed systemd file. And i tried to run it through command line and it display this error

[core:warn] [pid 19023] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot

But my /etc/apache2/apache2.conf seems to be right with cause i havent change it.

#
# The directory where shm and other runtime files will be stored.
#

DefaultRuntimeDir ${APACHE_RUN_DIR}

I will check syslog right now.

Any apache error in syslog the last 2 hours. Just a bunch of starting and stopping.

Dec 11 01:42:24 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 01:46:32 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 01:46:32 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 01:46:32 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 01:46:33 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 01:55:30 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 01:55:30 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 01:55:30 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 01:55:30 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 01:59:11 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 01:59:11 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 01:59:11 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 01:59:11 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 02:07:13 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 02:07:16 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 02:07:16 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 02:07:16 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 02:54:34 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 02:54:34 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 02:54:34 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 02:54:34 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 02:56:10 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 02:56:10 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 02:56:10 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 02:56:10 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 02:57:24 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 02:57:24 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 02:57:25 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 02:57:25 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 02:59:39 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 02:59:40 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 02:59:40 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 02:59:40 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 03:05:14 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 03:05:14 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 03:05:14 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 03:05:14 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 03:46:24 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 03:46:34 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 03:46:34 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 03:46:34 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 03:57:38 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 03:57:38 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 04:06:48 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 04:06:48 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.
Dec 11 04:07:10 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 04:07:11 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 04:07:11 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 04:07:11 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.

I am starting to think this has something to do with EC2 instance. I dont know

I’d test that hypothesis by removing the wsgi-related configuration items. (Leave the static and media file definitions for now.)

This means I’d remove these lines only:

    <Directory /home/ubuntu/byteb0x/byteb0x>
        <Files wsgi.py>
            Require all granted
        </Files>

    WSGIDaemonProcess byteb0x python-path=/home/ubuntu/byteb0x python-home=/home/ubuntu/byteb0x/venv
    WSGIApplicationGroup byteb0x
    WSGIScriptAlias / /home/ubuntu/byteb0x/byteb0x/wsgi.py

If, by removing those files, it starts to work, then the problem is somehow related to your Django configuration.

If it still doesn’t work, then it’s time to look at any configuration files related to your apache instance that you may have modified.

Okey right now my /etc/apache2/sites-available/byteb0x.conf looks like this :

<VirtualHost *:80>
    ServerAdmin bartek.cwb@gmail.com
    ServerName 00.000.00.000
    ServerAlias www.byteb0x.com byteb0x.com
    DocumentRoot /home/ubuntu/byteb0x
    <Directory /home/ubuntu/byteb0x>
        Require all granted
    </Directory>

    Alias /media /home/ubuntu/byteb0x/media
    Alias /static /home/ubuntu/byteb0x/staticfiles

    <Directory /home/ubuntu/byteb0x/staticfiles>
        Require all granted
    </Directory>

    <Directory /home/ubuntu/byteb0x/media>
    Require all granted
    </Directory>

</VirtualHost>

I restarted apache2

Dec 11 04:32:22 ip-172-31-46-124 systemd[1]: Stopping The Apache HTTP Server...
Dec 11 04:32:22 ip-172-31-46-124 systemd[1]: Stopped The Apache HTTP Server.
Dec 11 04:32:22 ip-172-31-46-124 systemd[1]: Starting The Apache HTTP Server...
Dec 11 04:32:22 ip-172-31-46-124 systemd[1]: Started The Apache HTTP Server.

And my var/log/apache2/error.log is :

[Mon Dec 11 04:32:22.823083 2023] [mpm_event:notice] [pid 19600:tid 140208186529664] AH00492: caught SIGWINCH, shutting down gracefully
[Mon Dec 11 04:32:22.960512 2023] [mpm_event:notice] [pid 19702:tid 140215753598848] AH00489: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Mon Dec 11 04:32:22.960635 2023] [core:notice] [pid 19702:tid 140215753598848] AH00094: Command line: '/usr/sbin/apache2'

Still cant acces. I havent changed any apache2 configuration files, 100% sure of that. But if i had to, what files should i be looking to? Or maybe is it easier to reinstall apache for now?

Do you have UFW (or iptables) running? If so, are all outbound ports open?

Do www.byteb0x.com and byteb0x.com exist yet? If not, remove this directive.

I have security rules on my AWS EC2, not configured as iptables as far as i know. Those rules allow inbound traffic from port 22(ssh/tcp) , 80(http/tcp) and 443 (https/tcp) for source 0.0.0.0/0 and allow all outbound trafic for any protocol, any traffic type and any port range whose destination is 0.0.0.0/0 Both for Ipv4 IP version.
Also byteb0x.com is bought by me but doesnt point to the IP yet. I will delete it right now from files.

/etc/apache2/apache2.conf would be the first place to check. Then anything that you may have modified in conf-enabled, mods-enabled or sites-enabled. (Do you still have the default enabled in sites-enabled?)

I’d do a purge on the existing packages first, then ensure the /etc/apache2 directory has been removed. That way you can feel confident that there’s nothing left over from the current installation.

I’d then do the install and check to see if it’s up and running before trying to add the application.

For now I will be looking on that.
Also i had used :

sudo a2dissite default.conf

So yes, I have the default in sites-enabled.

By the way I had it done, restarted apache2 and it still doesnt works.

I’d disable one or the other - again, just to try.

Okey, today I terminated my EC2 instances and configured it once again from start using the configuration showed at the beggining but on the /var/www folder. I figured out that due to using Brave browser it forces https on the request and that was why the server diaplayed this :

Thank you very much anyway. I’ve learned a lot thanks to you. I’ve seen in many other sections of the forum that you are very active. And i have to thank for your effort once again.