1

It's my first question in the community, i apologize in advance if I write something wrong

I developed an application in Python (Django) and in the quality environment I am using gunicorn to provide the deploy: gunicorn --bind 0.0.0.0:8000 application.wsgi --daemon

On the same server, I use Apache to listen to port 443 (https://) and redirect requests to Gunicorn via Proxy like this:

  <VirtualHost *:443>
  
        ServerName example.com   

        ProxyRequests Off
        ProxyPreserveHost On
        
        <Proxy *>
                Require all granted
                Allow from all
        </Proxy>

        ProxyPass / http://example.com:8000/
        ProxyPassReverse / http://example.com:8000/

        # SSL
        SSLEngine On

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        #Include conf-available
        SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>

Everything works perfectly, I can access it via https, except for the static files.

I followed the recommendation of the documentation, executed the command collectstatic and the files were generated in the folder I configured (/static) in settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/') 

I took advantage of the fact that I already had Apache installed, I tried to add in the same VirtualHost an alias to the /static directory, like this:

Alias /static "/home/ubuntu/example/static/"
<Directory "/home/ubuntu/example/static">
      Order allow,deny  
      Allow from all
      Require all granted
</Directory>

The complete configuration of VirtualHost looks like this:

 <VirtualHost *:443>
  
        ServerName example.com  

        Alias /static "/home/ubuntu/example/static/"
        <Directory "/home/ubuntu/example/static">
              Order allow,deny  
              Allow from all
              Require all granted
        </Directory>

        ProxyRequests Off
        ProxyPreserveHost On
        
        <Proxy *>
                Require all granted
                Allow from all
        </Proxy>

        ProxyPass / http://example.com:8000/
        ProxyPassReverse / http://example.com:8000/

        # SSL
        SSLEngine On

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        #Include conf-available
        SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>

However when trying to access the files in this directory I always get one:

Not Found - The requested resource was not found on this server.

I analyzed error.log and access.log and didn't even hit the request in the logs.

Adding the same alias to another Virtualhost on Port 80, it works normally. I believe the problem lies in adding this alias to a specific VirtualHost for port 443

Can you help me?

0

1 Answer 1

1

After much difficulty, i identified the error.

I needed to include an exception rule in ProxyPass, everything was fine with the shortcut.

I included this line:

ProxyPass /static!
ProxyPass / http://example.com:8000/

This post helped me:

How to add exceptions to apache reverse proxy rules

Not the answer you're looking for? Browse other questions tagged .