-
-
Notifications
You must be signed in to change notification settings - Fork 38
Guide: Installing AMP and Wordpress together
This is a small guide to showcase how AMP and Wordpress can coexist on the same system. This guide is based on a debian 10 (buster) system, so some of the configs may vary a little if you use another distribution.
At the end of this guide you should have a webserver where AMP resides on a subdomain, and your Wordpress is on your main domain. Both which will be on HTTPS, with any connection to HTTP redirected to HTTPS.
Prerequisites:
- A clean debian 10 system
- Basic knowledge of linux (usage of vi/nano)
- Access to domain controls, and knowledge about adding CNAMES.
- Knowledge of how to setup Wordpress
Be sure to add CNAMES for your domain, in this guide we will use: amp.domain.com, www.domain.com and domain.com
- Install AMP - https://cubecoders.com/AMPInstall
IMPORTANT NOTES:
- During the install of AMP, its important that when it asks for a domain, that you type in the subdomain you want to use for AMP fx. amp.domain.com
- When it asks if it should be installed as HTTPS/SSL, say yes.
- If Certbot asks if it should redirect all HTTP connections to HTTPS hit no
- Install Wordpress - I can recommend this guide to install it: Installing Wordpress
IMPORTANT NOTES:
- When it asks for which domain it should be installed on, write: http://domain.com (we will change it to https://domain.com later)
- Rerunning certbot to obtain certificates for all domains. This will add the extra domains to your certificates, so they can all run on SSL
- Command will look something like this:
sudo certbot -d amp.domain.com -d www.domain.com -d domain.com
- If certbot asks if it should redirect all HTTP to HTTPS, say no!
These samples are taken directly from a working production envirenment, so they should work right out of the box, with minor changes to web root, and ofc the server_names.
Do not just copy/paste these configs, but compare them to your own. You might only need to change a line or two, so it'll be more work if you copy/paste the configs.
root /var/www/html/wordpress;
index index.php index.html index.htm;
server_name domain.com www.domain.com;
access_log /var/log/nginx/wordpress_access.log;
error_log /var/log/nginx/wordpress_error.log;
client_max_body_size 64M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_read_timeout 3600s;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/amp.domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/amp.domain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = www.domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
server_name domain.com www.domain.com;
return 301 https://$host$request_uri; # managed by Certbot
}
#Generated by CubeCoders AMP for ADS
server {
server_name amp.domain.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-AMP-Scheme $scheme;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
client_max_body_size 10240M;
error_page 502 /NotRunning.html;
location = /NotRunning.html {
root /opt/cubecoders/amp/shared/WebRoot;
internal;
}
location /shared/ {
alias /opt/cubecoders/amp/shared/WebRoot/;
}
}
listen [::]:443 ssl http2 ipv6only=on; # managed by Certbot
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/amp.domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/amp.domain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = amp.domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name amp.domain.com;
return 404; # managed by Certbot
}
- Restart your nginx, and see if things work as intended.
http://amp.domain.com and https://amp.domain.com should reach your AMP.
http://domain.com and https://domain.com should reach your Wordpress.
- Remember to change your wordpress settings to https://domain.com in your general settings.
This is meant as a showcase on a clean system, if you attempt this on an already configured nginx with other subdomains, you need to take those into account aswell.