Skip to content

Commit da87142

Browse files
committed
fix error in docs relating to setting hostname
1 parent a41a5be commit da87142

File tree

4 files changed

+75
-40
lines changed

4 files changed

+75
-40
lines changed

README.md

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,27 @@ When launching your AMI put the following in as `USERDATA` replacing `{{yourhost
4848

4949
```
5050
#!/bin/bash
51-
echo "export SERVER_HOSTNAME=yourhost.com" > /home/ec2-user/host.sh
51+
echo "SERVER_HOSTNAME=yourhost.com" > /home/ec2-user/host.sh
5252
```
5353

5454
It will look like this:
5555

56-
![Image of Default Wordpress Site](./ami-userdata.png)
56+
![Image of Default Wordpress Site](./ami-userdata2.png)
57+
58+
Close up:
5759

60+
![Image of Default Wordpress Site](./ami-userdata.png)
5861

59-
This will set the host name in your instance.
62+
Setting `USERDATA` will set the host name in your instance. If you do not set the `USERDATA`. we will use the instance host name set by AWS.
6063

6164
```
6265
#!/bin/bash
63-
echo "export SERVER_HOSTNAME=yourhost.com" > /home/ec2-user/host.sh
66+
echo "SERVER_HOSTNAME=yourhost.com" > /home/ec2-user/host.sh
6467
```
6568

66-
We require you use the a domain (`yourhost.com` or `www.yourhost.com`). This will ensure that everything is correctly auto configured on your behalf. For example, if you set `www.yourhost.com` NGINX will set it a server as `www.yourhost.com`.
69+
We require you use the a domain (`yourhost.com` or `www.yourhost.com`). This will ensure that everything is correctly auto configured on your behalf. For example, if you set `www.yourhost.com` NGINX will set it a server as `www.yourhost.com`. The domain `yourhost.com` is a placeholder, an example, Do not blindly use `yourhost.com`!! It seems obvious, but not to everyone.
6770

68-
If you decide not to set DNS via `USERDATA` go to **Step 3**.
71+
Remember, if you decide not to set DNS via `USERDATA` go to **Step 3**. You will need to manually configure SSL. We will install self-signed SSL certs as a temporary solution until you can configure everything according to the process outlined in Step 3.
6972

7073
### IMPORTANT
7174
Make sure your IP (x.x.x.x) points to a DNS A Record uses the domain you set via USERDATA ( `yourhost.com` or `www.yourhost.com` ).
@@ -96,6 +99,7 @@ If you want to log into the `wp-admin` console, you need to get your password. T
9699

97100
You can also get it from AWS console by looking at the `Get System Logs` and scrolling for `WORDPRESS_ADMIN_PASSWORD`. You can also SSH into your instance and get the creds.
98101

102+
99103
# Step 3: Manual Setup of SSL
100104
Did you setup DNS via `USERDATA`? No, then you need to set your domain name and get your SSL setup. If you do not set your host via AMI `USERDATA` we will install self-signed SSL certificates. This will be enough to get you up and running. The following section describes how you can manually set your server host and install SSL certificates.
101105

@@ -111,7 +115,7 @@ You will certainly want to change these.
111115
To keep things organized we default to using [`letsencrypt`](https://letsencrypt.org/) for SSL certificates/keys, paths and naming conventions. Even if you are using your own certs, follow the naming conventions detailed below.
112116

113117
In keeping with the `letsencrypt` conventions make sure your certs are using the same naming scheme:
114-
```
118+
```bash
115119
/etc/letsencrypt/live/${NGINX_SERVER_NAME}/;
116120
├── server
117121
│ ├── cert.pem
@@ -128,38 +132,55 @@ ssl_trusted_certificate /etc/letsencrypt/live/{{NGINX_SERVER_NAME}}/chain.pem;
128132
Even if you are not using letsencrypt simple repurpose the path above.
129133

130134
## Using `certbot` for `letsencrypt` SSL certs
131-
On your **host**, not in the Docker image, we pre-installed `certbot`. The install process looks something like this if you need to rerun it yourself:
135+
On your **host**, not in the Docker image, we pre-installed the `certbot` Docker image.
136+
137+
First, make sure your `NGINX` is not running. You need to do this because `cerbot` needs to have post 80 and 443 open. If `NGINX` is running, there will be a port conflict. This will gracefully close down everything:
132138

133-
If your run into an errors with certbot, trying running these commands:
134139
```bash
135-
rm -rf ~/.local/share/letsencrypt
136-
rm -rf /opt/eff.org/*
137-
# Install for Lets Encrypt
138-
mkdir ~/src
139-
cd ~/src || exit
140-
wget http://www.dest-unreach.org/socat/download/socat-1.7.3.0.tar.gz
141-
tar -xf socat-1.7.3.0.tar.gz
142-
cd socat-1.7.3.0 || exit
143-
./configure --prefix=$HOME
144-
make
145-
make install
146-
147-
curl https://get.acme.sh | sh
148-
149-
certbot-auto certonly -n --debug --agree-tos --standalone -d $SERVER_HOSTNAME > /dev/null
140+
/usr/local/bin/docker-compose -f /home/ec2-user/wordpress.yml down --remove-orphans
150141
```
151142

152-
## Mount your certs
153-
If you when down the path of using USERDATA, this has been done for you. For reference, we mount your certs directory on the host to: `/etc/letsencrypt/live/<yourdomain>`. If you need to set SSL certs manually, then read on.
143+
Next, provision your SSL certificates:
144+
145+
```bash
146+
docker pull certbot/certbot
147+
148+
docker run -it --rm -p 80:80 -p 443:443 --name certbot -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/lib/letsencrypt:/var/lib/letsencrypt" certbot/certbot certonly -n --debug --agree-tos --email user@gmail.com --standalone -d ${SERVER_HOSTNAME}
149+
```
150+
151+
Then start up all your services again:
152+
```bash
153+
/usr/local/bin/docker-compose -f /home/ec2-user/wordpress.yml up -d --remove-orphans
154+
```
155+
156+
157+
## Automate `letsencrypt` SSL renewals
158+
You will need to setup a renewal process. The docs say check twice a day for changes. Lets add the renewal process to cron:
159+
```bash
160+
cat << EOF > /tmp/crontab.conf
161+
55 4,16 * * * /opt/eff.org/certbot/venv/local/bin/pip install --upgrade certbot
162+
59 4,16 * * * certbot-auto certonly -n --debug --agree-tos --pre-hook="docker stop nginx" --post-hook="docker start nginx" --standalone -d *.yourhost.com > /dev/null
163+
EOF
164+
```
165+
Lastly, add everything to cron via `cat /tmp/crontab.conf | crontab - && crontab -l`
166+
167+
We have also installed ACME.sh (https://github.com/Neilpang/acme.sh). If you prefer, you can use this as your client for Lets Encrypt!
168+
169+
## Do you already have SSL certs?
170+
For reference, we mount SSL certs to a directory on the host: `/etc/letsencrypt/live/<yourdomain>`.
171+
172+
If you need to set SSL certs manually because you have them already via some other third party, then read on.
154173

155174
### Edit `wordpress.yml`
156-
This assumes you already have the certs on your host here `/etc/letsencrypt/live/<yourdomain>`.
175+
First, make sure you place your certs on the host in this path: `/etc/letsencrypt/live/<yourdomain>`.
157176

158-
Next, we want to add the paths to the Docker compose file under the `nginx` block. Here is the where you can find the file: `/home/ec2-user/wordpress.yml`
177+
Next, we want to add the path to your certs into the Docker compose file. In the compose yml file see the SSL certs under the `nginx` block.
159178

160-
You will already see `- wordpress_data:/usr/share/nginx/html` present. You want to add the following into the compose file. Remember to put use the actual domain you used with certbot:
179+
Here is the where you can find the file on the host: `/home/ec2-user/wordpress.yml`
161180

162-
```docker
181+
You will already see `- wordpress_data:/usr/share/nginx/html` present. You want to add the following into the compose file. Remember to put use the actual domain you want to use in place of `<yourdomain>`:
182+
183+
```bash
163184
volumes:
164185
- wordpress_data:/usr/share/nginx/html
165186
- /etc/letsencrypt/live/<yourdomain>/fullchain.pem:/etc/letsencrypt/live/<yourdomain>/fullchain.pem
@@ -172,22 +193,28 @@ If you do not have a `chain.pem`, simply copy the `fullchain.pem` over.
172193
```bash
173194
cp /etc/letsencrypt/live/<yourdomain>/fullchain.pem /etc/letsencrypt/live/<yourdomain>/chain.pem
174195
```
196+
After making the change to the compose file, save it. Then run this command to start everything:
175197

176-
## Automate SSL renewals
177-
You will need to setup a renewal process. The docs say check twice a day for changes. Lets add the renewal process to cron:
178198
```bash
179-
cat << EOF > /tmp/crontab.conf
180-
55 4,16 * * * /opt/eff.org/certbot/venv/local/bin/pip install --upgrade certbot
181-
59 4,16 * * * certbot-auto certonly -n --debug --agree-tos --pre-hook="docker stop nginx" --post-hook="docker start nginx" --standalone -d *.yourhost.com > /dev/null
182-
EOF
199+
/usr/local/bin/docker-compose -f /home/ec2-user/wordpress.yml up -d --remove-orphans
183200
```
184-
Lastly, add everything to cron via `cat /tmp/crontab.conf | crontab - && crontab -l`
185201

186-
We have also installed ACME.sh (https://github.com/Neilpang/acme.sh). If you prefer, you can use this as your client for Lets Encrypt!
187202

188203
# Docker Configuration
189204

190-
## Configuring your Docker container
205+
206+
## Starting and Stopping Your Docker Services
207+
208+
If you want to `start` all your services, the command is:
209+
```bash
210+
/usr/local/bin/docker-compose -f /home/ec2-user/wordpress.yml up -d --remove-orphans
211+
```
212+
If you want to `stop` all your services, the command is:
213+
```bash
214+
/usr/local/bin/docker-compose -f /home/ec2-user/wordpress.yml down --remove-orphans
215+
```
216+
217+
## Advanced Configuration
191218
When you SSH into your server go to your `HOME` directory. In there you will see a `wordpress.env` file that was created for you. This is used by your Docker containers to initialize various container settings.
192219

193220
Here is what is resident in the file:
@@ -237,7 +264,7 @@ The default username is set via `WORDPRESS_ADMIN` and is `admin`.
237264

238265
As always, keep your ENV file safe and secure.
239266

240-
### Advanced configuration
267+
### Only change if you know what you are doing
241268
Don't change any of the defaults for these unless you are a pro and understand what you are doing:
242269

243270
* `NGINX_DOCROOT` sets the default www directory. The containers default to `/usr/share/nginx/html` so it is best left unchanged.
@@ -292,10 +319,18 @@ You will likely want to dispatch logs to a service like Amazon Cloudwatch. This
292319
| latest | ami-deb3eea1 | 1.0.2 | 3.8 |
293320
| latest | ami-deb3eea1 | 1.0.1 | 3.8 |
294321

322+
323+
# Bad Gateway
324+
325+
If you happen to see a bad gateway error, hard reload your browser. It is possible you have something in your browser cache that is causing this:
326+
327+
![Image of Bad Gateway](./bad-Gateway.png)
328+
295329
# Issues
296330

297331
If you have any problems with or questions about this image, please contact us through a GitHub issue.
298332

333+
299334
# Contributing
300335

301336
You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.

ami-userdata.png

-341 Bytes
Loading

ami-userdata2.png

127 KB
Loading

bad-gateway.png

13.3 KB
Loading

0 commit comments

Comments
 (0)