Question

How do i remove Apache2 Ubuntu Default Page?

Please, kindly need help, after deployed flask application on ubuntu 14 into this path var/www/FlaskApp, Accessing my IP, it display correctly, So, i decided to point my domain to digital ocean which display “Apache2 Ubuntu Default Page”, please how do i remove this default page to display the content on var/www/FlaskApp

Here is my folder structure

var/www
---------------------FlaskApp
--------------------------- templates
--------------------------- static
--------------------------- app.py
---------------------html
---------------------scrapy.cfg
```

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
September 26, 2023

Heya,

To resolve the issue of your domain showing the “Apache2 Ubuntu Default Page” instead of your Flask application, you will need to set up a Virtual Host in Apache for your Flask application and then disable the default configuration.

Having said that, you can just follow STEP 1 and STEP 3 and for a full guide, follow all steps.

Step 1: Set Up a Virtual Host for Your Flask App

  1. Create a Virtual Host File for Your Flask App Create a new configuration file in /etc/apache2/sites-available/ for your Flask application.
sudo nano /etc/apache2/sites-available/FlaskApp.conf
  1. Add the Following Configuration to the File Replace your_domain.com with your actual domain and adjust paths if necessary.
<VirtualHost *:80>
    ServerName your_domain.com
    ServerAdmin your_email@example.com
    WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
    <Directory /var/www/FlaskApp/FlaskApp/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /var/www/FlaskApp/FlaskApp/static
    <Directory /var/www/FlaskApp/FlaskApp/static/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Step 2: Create the WSGI File

  1. Navigate to Your Flask App Directory
cd /var/www/FlaskApp
  1. Create a WSGI File for Your Flask App\
sudo nano flaskapp.wsgi
  1. Add the Following Configuration to the WSGI File
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")

from FlaskApp import app as application
application.secret_key = 'YourSecretKey'

Step 3: Enable the New Virtual Host

  1. Enable Your Flask App Configuration
sudo a2ensite FlaskApp
sudo a2dissite 000-default.conf

then restart apache

systemctl restart apache2

Step 4: Update Your Application’s Import in WSGI

Make sure the application object in your flaskapp.wsgi file matches the one in your app.py file. If your app.py file looks something like this:

from flask import Flask
app = Flask(__name__)

# More code...

if __name__ == "__main__":
    app.run()

Then your flaskapp.wsgi file should import it as:

from FlaskApp import app as application

Final Note

Remember to replace placeholders in the configurations with actual values relevant to your application, such as your_domain.com, your_email@example.com, and YourSecretKey

Hello,

I was able to solve this issue by below steps:

myproject here is depend on what you previously setup.

  1. Edit: $ sudo vim /etc/nginx/sites-available/myproject

  2. Find: server { listen 80; server_name server_domain_or_IP;

  3. Replace server_domain_or_IP with your domain name.

  4. Restart: $ sudo service apache2 restart

I’m having the exact same issue. I can’t get rid of the apache default page. I’m using apache as a reverse proxy only, so no content is served by apache itself. The reverse proxy works for any URL requested except for the main /, in that case I always get the default page. Already tried all mentioned things here.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel