Skip to content

Commit 26b2dfe

Browse files
authored
Merge pull request geerlingguy#1071 from oxyc/nginx-ssl
Add docs on using HTTPS with Nginx
2 parents 4c94124 + 6e5fda6 commit 26b2dfe

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

docs/extras/ssl.md

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ To enable SSL support for you virtual hosts you first need a certificate file. Y
22

33
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout example.key -out example.crt
44

5-
Place the files in your project directory and add the following to your `config.yml`.
5+
Place the files in your project directory and edit your `config.yml`.
6+
7+
_If you're using an actual production certificate you should of course **NOT** track it in git but transfer it to the VM before running `vagrant provision`_
8+
9+
### Apache
10+
11+
Add the following to your `config.yml`:
612

713
```yaml
814
apache_vhosts_ssl:
@@ -14,14 +20,32 @@ apache_vhosts_ssl:
1420
ProxyPassMatch ^/(.*\.php(/.*)?)$ "fcgi://127.0.0.1:9000{{ drupal_core_path }}"
1521
```
1622
17-
_If you're using an actual production certificate you should of course **NOT** track it in git but transfer it to the VM before running `vagrant provision`_
18-
1923
For a list of all configuration options see the [`geerlingguy.apache` Ansible role's README](https://github.com/geerlingguy/ansible-role-apache#readme).
2024

21-
### Using Ubuntu's snakeoil certificate
25+
### Nginx
26+
27+
Modify your nginx host configuration by adding the following `extra_parameters` to the first entry in `nginx_hosts`:
28+
29+
```yaml
30+
- server_name: "{{ drupal_domain }} www.{{ drupal_domain }}"
31+
root: "{{ drupal_core_path }}"
32+
is_php: true
33+
extra_parameters: |
34+
listen 443 ssl;
35+
ssl_certificate /vagrant/example.crt;
36+
ssl_certificate_key /vagrant/example.key;
37+
ssl_protocols TLSv1.1 TLSv1.2;
38+
ssl_ciphers HIGH:!aNULL:!MD5;
39+
```
40+
41+
For a list of all configuration options see the [`geerlingguy.nginx` Ansible role's README](https://github.com/geerlingguy/ansible-role-nginx#readme).
42+
43+
## Using Ubuntu's snakeoil certificate
2244

2345
If you are using Ubuntu as your base OS and you want to get started quickly with a local development environment you can use the snakeoil certificate that is already generated.
2446

47+
#### Apache
48+
2549
```yaml
2650
apache_vhosts_ssl:
2751
- servername: "{{ drupal_domain }}"
@@ -31,3 +55,30 @@ apache_vhosts_ssl:
3155
extra_parameters: |
3256
ProxyPassMatch ^/(.*\.php(/.*)?)$ "fcgi://127.0.0.1:9000{{ drupal_core_path }}"
3357
```
58+
59+
#### Nginx
60+
61+
```yaml
62+
- server_name: "{{ drupal_domain }} www.{{ drupal_domain }}"
63+
root: "{{ drupal_core_path }}"
64+
is_php: true
65+
extra_parameters: |
66+
listen 443 ssl;
67+
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
68+
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
69+
ssl_protocols TLSv1.1 TLSv1.2;
70+
ssl_ciphers HIGH:!aNULL:!MD5;
71+
```
72+
73+
## Tips & Tricks
74+
75+
To automatically add a SSL virtual host for every Apache host defined in `apache_vhosts` you can add the following to your `config.yml`:
76+
77+
```yaml
78+
apache_vhost_ssl_parameters:
79+
certificate_file: "/etc/ssl/certs/ssl-cert-snakeoil.pem"
80+
certificate_key_file: "/etc/ssl/private/ssl-cert-snakeoil.key"
81+
82+
# Generate a SSL virtual host for every regular vhost.
83+
apache_vhosts_ssl: "{% set vhosts = [] %}{% for vhost in apache_vhosts %}{% if vhosts.append(vhost|combine(apache_vhost_ssl_parameters)) %}{% endif %}{% endfor %}{{ vhosts }}"
84+
```

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pages:
2828
- 'Use MariaDB instead of MySQL': 'extras/mariadb.md'
2929
- 'Use PostgreSQL instead of MySQL': 'extras/postgresql.md'
3030
- 'Use Node.js and NPM': 'extras/nodejs.md'
31-
- 'Use SSL vhosts with Apache': 'extras/ssl.md'
31+
- 'Use SSL vhosts with Apache/Nginx': 'extras/ssl.md'
3232
- 'View Logs with Pimp my Log': 'extras/pimpmylog.md'
3333
- 'Profile Code - XHProf, Blackfire, Xdebug': 'extras/profile-code.md'
3434
- 'Debug Code with XDebug': 'extras/xdebug.md'

0 commit comments

Comments
 (0)