Nathan Wailes
Nathan Wailes

Reputation: 12242

How to have an Apache-served Flask website with a WordPress blog at /blog?

I realize there are multiple similar questions already but I could not seem to find an answer that made it clear to me what I needed to do:

I have a DigitalOcean droplet which is serving a Flask application. I would now like to have a WordPress blog at /blog. I went through DigitalOcean's WordPress setup instructions but I they did not include a description of how to modify the Apache .conf file to point to the WordPress index.php file.

I tried adding an Alias to my .conf file but it does not work. When I go to /blog right now I see the default Apache "It works!" page. However, if I go to www.rhymecraft.guru/blog/wp-admin it does load the admin panel.

Apache .conf file

(Note that I installed WordPress into /var/www/html.)

WSGIDaemonProcess rhymecraft.guru processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup rhymecraft.guru

<VirtualHost *:80>
        ServerName www.rhymecraft.guru
        ServerAlias rhymecraft.guru
        ServerAdmin [email protected]

        Alias /blog /var/www/html
        WSGIScriptAlias / /var/www/rhymecraft/server/rhymecraft.wsgi

        DocumentRoot /var/www/rhymecraft/server

        Alias /robots.txt /var/www/rhymecraft/server/robots.txt
        Alias /favicon.ico /var/www/rhymecraft/server/robots.txt

        <Directory /var/www/rhymecraft/server>
            Order allow,deny
            Allow from all
        </Directory>

        Alias /static /var/www/rhymecraft/server/static     

        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.rhymecraft.guru [OR]
RewriteCond %{SERVER_NAME} =rhymecraft.guru
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
                ServerName www.rhymecraft.guru
                ServerAlias rhymecraft.guru
                ServerAdmin [email protected]

                Alias /blog /var/www/html
                WSGIScriptAlias / /var/www/rhymecraft/server/rhymecraft.wsgi

                DocumentRoot /var/www/rhymecraft/server

                Alias /robots.txt /var/www/rhymecraft/server/robots.txt
                Alias /favicon.ico /var/www/rhymecraft/server/robots.txt

                <Directory /var/www/rhymecraft/server>
                        Order allow,deny
                        Allow from all
                </Directory>

                Alias /static /var/www/rhymecraft/server/static

                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/rhymecraft.guru/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/rhymecraft.guru/privkey.pem
</VirtualHost>

Related questions and why they didn't answer my question

Upvotes: 2

Views: 473

Answers (1)

Nathan Wailes
Nathan Wailes

Reputation: 12242

I got it working.

Two things I needed to do:

  1. I needed to have the line Alias /blog /var/www/html in both VirtualHost entries. At first I had only put it in the port 80 (normal-HTTP-traffic) entry, but forgot to put it in the port 443 (HTTPS traffic) entry.
    • Note that you'll only have these two VirtualHost records if you're using HTTPS. I'm using Cloudflare and forcing all requests to the website to use HTTPS, so the fact that I forgot to add the Alias record to the port 443 VirtualHost record was enough to make it appear to not be working.
  2. I needed to delete the default Apache index.html file that was in the /var/www/html directory.
    • Apache was preferring to use that over the index.php file that WordPress had added to the directory.

Upvotes: 1

Related Questions