Goal:
You will need the scripts linked below. By the end of this lesson, you will:
- Deploy a Wagtail site behind an Nginx reverse proxy with SSL encryption.
- Migrate a WordPress website to Wagtail.
- Optimize SEO and images for better performance and search engine ranking.
Step 1: Deploy Wagtail on Debian Behind Nginx with SSL
Before migrating your WordPress content, you must set up Wagtail on your new server. We will use the deploy_wagtail.sh
script to automate this process.
1.1 Upload and Run the Deployment Script
- Transfer the script to your Wagtail server via SCP:
scp deploy_wagtail.sh user@wagtail-server:/tmp/
- Log into the Wagtail server:
ssh user@wagtail-server
- Make the script executable:
chmod +x /tmp/deploy_wagtail.sh
- Run the script:
sudo /tmp/deploy_wagtail.sh
1.2 Script Functionality
The script will:
✅ Install Wagtail, PostgreSQL, Nginx, and Certbot.
✅ Prompt for a domain name to configure Nginx.
✅ Set up SSL encryption using Let’s Encrypt.
✅ Restart all necessary services (Gunicorn, Nginx).
1.3 Verify Deployment
- Visit your domain (e.g.,
https://yourdomain.com
). - You should see the Wagtail welcome page.
- Log into Wagtail Admin:
https://yourdomain.com/admin/
- Default Admin Credentials:
- Username: admin
- Password: (set during installation)
Step 2: Export WordPress Data
We will use the script export_wordpress.sh
on the WordPress server to export the posts, pages, the database, and media files into a single compressed .tar.gz
archive.
- Log into your WordPress server.
- Upload
export_wordpress.sh
to the server. - Make the script executable:
chmod +x export_wordpress.sh
- Run the script:
./export_wordpress.sh
You will be prompted to enter:- WordPress database name (e.g.,
wordpress_db
). - WordPress database user and password.
- WordPress site directory.
wordpress_export.tar.gz
file containing all necessary data (content, database dump, and media). - WordPress database name (e.g.,
Step 3: Transfer the Export File to the Wagtail Server
Use SCP or another file transfer method to move the wordpress_export.tar.gz
file from the WordPress server to the Wagtail server.
Example using SCP:
scp wordpress_export.tar.gz user@wagtail-server:/tmp/
Step 4: Import WordPress Data into Wagtail
On the Wagtail server, we will use the import_wordpress_to_wagtail.sh
script to import the data (posts, pages, media) into the new Wagtail site.
- Log into your Wagtail server.
- Upload
import_wordpress_to_wagtail.sh
to the server. - Make the script executable:
chmod +x import_wordpress_to_wagtail.sh
- Run the script:
sudo ./import_wordpress_to_wagtail.sh
You will be asked for:- Wagtail project name (e.g.,
mywagtailsite
). - Domain (e.g.,
example.com
).
- Extract the content from
wordpress_export.tar.gz
. - Import posts and pages into Wagtail.
- Create redirects for WordPress URLs (e.g.,
/category/
,/tag/
). - Place media files in the Wagtail media directory.
- Wagtail project name (e.g.,
Step 5: Optimize Images and Permalinks
After migration, we’ll focus on optimizing images and restructuring permalinks to ensure that they’re SEO-friendly.
- Upload
optimize_images_and_permalinks.sh
to the Wagtail server. - Make the script executable:
chmod +x optimize_images_and_permalinks.sh
- Run the script:
sudo ./optimize_images_and_permalinks.sh
The script will:- Compress images (JPEG and PNG) to reduce page load times.
- Convert images to WebP format for modern browsers.
- Update permalinks to follow SEO-friendly practices (e.g., removing
/index.php/
and/category/
from URLs). - Restart services to apply changes (Gunicorn and Nginx).
Step 6: SEO Optimization After Migration
Once the content has been migrated and optimized, it’s essential to fine-tune the SEO aspects of your site. This includes:
1. SEO-Friendly URLs:
- Ensure all URLs are clean, readable, and reflect the content (e.g.,
/about-us/
instead of/index.php/about-us/
). - The script automatically handles this during the migration, but check the URLs in Wagtail’s admin for consistency.
2. Meta Tags and Titles:
- Wagtail doesn’t automatically import SEO metadata like title tags, meta descriptions, and Open Graph tags from WordPress. To address this, you can use a custom Wagtail SEO app.
- Install a Wagtail SEO package such as wagtail-seo to manage meta tags, social media integration, and other SEO features.
Example installation:
pip install wagtail-seo
After installation, you can add the SEO fields to your Wagtail page models, like so:
from wagtailseo.models import SeoFields
class MyPage(Page, SeoFields):
...
3. Structured Data:
Structured data helps search engines understand the content on your site better. Adding JSON-LD markup for articles, reviews, and other content types will help improve your SEO.
You can include structured data in your templates:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "{{ page.title }}",
"author": "{{ page.author }}",
"datePublished": "{{ page.date_published|date:'YYYY-MM-DD' }}",
"image": "{{ page.featured_image.url }}"
}
</script>
4. XML Sitemap:
Generate an XML sitemap for search engines to crawl your website. If using Wagtail 2.14+, you can install the wagtail-sitemap
package for automatic sitemap generation.
Install the package:
pip install wagtail-sitemap
Configure it in your settings:
INSTALLED_APPS = [
...
'wagtail.contrib.sitemaps',
'wagtail.sitemaps',
]
This will automatically create a sitemap at /sitemap.xml
.
Step 7: Verify and Test the Site
After running all scripts and SEO optimizations, verify that the site is working properly:
- Check the Wagtail site:
- Visit the home page, posts, and pages to ensure everything looks good.
- Verify redirects:
- Test URLs from your WordPress site (e.g.,
/category/my-category/
) to ensure they properly redirect to their new Wagtail equivalents.
- Test URLs from your WordPress site (e.g.,
- SEO Testing:
Conclusion
You have now successfully migrated a WordPress site to Wagtail, optimized images, and implemented SEO best practices.
By following this lesson, you will:
- Retain your site’s SEO performance with properly structured URLs, metadata, and redirects.
- Ensure faster page loads with optimized images and WebP conversion.
- Integrate structured data and sitemaps to help search engines understand and index your content.
🚀 Your site is now set up for success in both content management and SEO performance!