Skip to content

Commit

Permalink
Installation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
devemlight committed Apr 18, 2019
1 parent cb4b338 commit 45a0cca
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 20 deletions.
51 changes: 33 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
# Wildcard laravel nginx letsencrypt configurations
# Configurations: secure laravel + wildcard nginx + wildcard letsencrypt https

This script allows you to quickly deploy the latest version of nginx web server, configure wildcard domain routing, install a secure ssl wildcard certificate through letsencrypt. This installation has been tested on **ubuntu 16.04** and **nginx 1.15.11**.

Based on [Nginx Server Configs](https://github.com/h5bp/server-configs-nginx).

## Installation

Tested on
### 0. Install nginx latest version [optional]

```bash
nginx -v

# nginx version: nginx/1.15.8
./bin/install-nginx.sh
```

### Wildcard
### 0. Install docker [optional]

```bash
sudo mkdir /etc/nginx/server-configs-nginx && sudo chown $(whoami) /etc/nginx/server-configs-nginx
git clone https://github.com/h5bp/server-configs-nginx.git /etc/nginx/server-configs-nginx
./bin/install-docker.sh
```

sudo mkdir /etc/nginx/base && sudo chown $(whoami) /etc/nginx/base
git clone https://github.com/isswp101/laravel-nginx-configs.git /etc/nginx/base
### 1. Install nginx configurations

```bash
./bin/install-configurations.sh <base_domain_name>
```

sudo cp /etc/nginx/base/nginx/nginx.conf /etc/nginx/nginx.conf
sudo cp /etc/nginx/base/nginx/conf.d/wildcard.conf /etc/nginx/conf.d/wildcard.conf
The following files will be created:

sudo systemctl reload nginx
```
/etc/nginx
|- server-configs-nginx // base configurations from h5bp
|- base // bash nginx configurations
|- conf.d
| - default.conf
| - wildcard.conf
|- nginx.conf
```

### SSL
### 2. Install wildcard ssl certificates using letsencrypt

```bash
./certbot/certonly.sh
sudo wget https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/options-ssl-nginx.conf -P /etc/letsencrypt
sudo openssl dhparam -out /etc/letsencrypt/ssl-dhparams.pem 2048
sudo systemctl reload nginx
./bin/install-ssl.sh <base_domain_name>
```

The following files will be created:

```
/etc/letsencrypt
|- live
|- options-ssl-nginx.conf
|- ssl-dhparams.pem
```
31 changes: 31 additions & 0 deletions bin/install-configurations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

if [ "$1" = "" ]
then
echo "Usage: $0 <base_domain_name>"
exit 1
fi

# Clone h5bp
sudo mkdir /etc/nginx/server-configs-nginx && sudo chown $(whoami) /etc/nginx/server-configs-nginx
git clone https://github.com/h5bp/server-configs-nginx.git /etc/nginx/server-configs-nginx

# Clone base configurations
sudo mkdir /etc/nginx/base && sudo chown $(whoami) /etc/nginx/base
git clone https://github.com/devemio/laravel-nginx-configs.git /etc/nginx/base

# Install default and wildcard domain configurations
sudo cp /etc/nginx/base/nginx/nginx.conf /etc/nginx/nginx.conf
sudo cp /etc/nginx/base/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
sudo cp /etc/nginx/base/nginx/conf.d/wildcard.conf /etc/nginx/conf.d/wildcard.conf

# Replace path to ssl certificates
sed -i "s|/etc/letsencrypt/live/example.com|/etc/letsencrypt/live/$1|g" /etc/nginx/conf.d/default.conf
sed -i "s|/etc/letsencrypt/live/example.com|/etc/letsencrypt/live/$1|g" /etc/nginx/conf.d/wildcard.conf

# Restart nginx
sudo systemctl reload nginx

# Install base html page
sudo cp /etc/nginx/base/html/404.html /var/www/html/index.html
sudo chown $(whoami) /var/www/html/index.html
15 changes: 15 additions & 0 deletions bin/install-nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

sudo sh -c "echo 'deb http://nginx.org/packages/mainline/ubuntu/ '$(lsb_release -cs)' nginx' > /etc/apt/sources.list.d/nginx.list"
sudo sh -c "echo 'deb-src http://nginx.org/packages/mainline/ubuntu/ '$(lsb_release -cs)' nginx' >> /etc/apt/sources.list.d/nginx.list"

wget https://nginx.org/keys/nginx_signing.key -O - | sudo apt-key add -

sudo apt update
sudo apt install nginx

sudo systemctl start nginx
sudo systemctl status nginx

sudo ufw allow https comment 'nginx'
sudo ufw allow http comment 'nginx'
12 changes: 12 additions & 0 deletions bin/install-ssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

if [ "$1" = "" ]
then
echo "Usage: $0 <base_domain_name>"
exit 1
fi

sudo ./certbot/certonly.sh $1
sudo wget https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/options-ssl-nginx.conf -P /etc/letsencrypt
sudo openssl dhparam -out /etc/letsencrypt/ssl-dhparams.pem 2048
sudo systemctl reload nginx
10 changes: 8 additions & 2 deletions certbot/certonly.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/bash

sudo docker run -it --rm --name certbot \
if [ "$1" = "" ]
then
echo "Usage: $0 <base_domain_name>"
exit 1
fi

docker run -it --rm --name certbot \
-v "/etc/letsencrypt:/etc/letsencrypt" \
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
certbot/certbot certonly \
Expand All @@ -9,4 +15,4 @@ sudo docker run -it --rm --name certbot \
--manual-public-ip-logging-ok \
--preferred-challenges dns-01 \
--server https://acme-v02.api.letsencrypt.org/directory \
-d example.com -d *.example.com
-d $1 -d *.$1

0 comments on commit 45a0cca

Please sign in to comment.