# How to Install Discourse Using Nginx for SSL: Step-by-Step Tutorial

> Learn how to install Discourse with Nginx managing the SSL port. Follow this comprehensive step-by-step guide to seamlessly set up your Discourse forum with Nginx handling SSL.

## Prerequisites

* Ubuntu server
    
* Domain name configured
    
* Root/sudo access
    
* Minimum 2GB RAM recommended
    

## Step 1: Install Required Packages

```bash
sudo apt update -y && apt upgrade -y
sudo apt install wget curl zip git docker.io nginx -y
sudo reboot
```

## Step 2: Install Discourse

```bash
sudo mkdir /var/discourse
sudo git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse
```

## Step 3: Configure Discourse

Edit the app.yml configuration file:

```bash
sudo nano /var/discourse/containers/app.yml
```

Make these important changes:

```yaml
# Comment out these lines
#- "templates/web.ssl.template.yml"
#- "templates/web.letsencrypt.ssl.template.yml"

# Add this line
- "templates/web.socketed.template.yml"

# Comment out expose section
#expose:
#  - "80:80"
#  - "443:443"

# Add in env section
env:
  DISCOURSE_FORCE_HTTPS: true
```

## Step 4: Build Discourse

```bash
cd /var/discourse
./launcher rebuild app
```

## Step 5: Configure Nginx

Create a new Nginx configuration:

```bash
sudo nano /etc/nginx/sites-available/discourse
```

Add this configuration (replace [example.com](http://example.com) with your domain):

```nginx
server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;
    
    ssl_certificate /etc/ssl/certs/your_ssl_cert.bundle;
    ssl_certificate_key /etc/ssl/private/your_ssl_cert.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    
    location / {
        proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
```

## Step 6: Enable and Start Nginx

```bash
sudo ln -s /etc/nginx/sites-available/discourse /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl enable nginx
sudo systemctl start nginx
```

## Step 7: SSL Certificate Setup

If using Let's Encrypt:

```bash
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com
```

## Important Notes

* Make sure your domain's DNS is properly configured before starting
    
* The Nginx configuration assumes you're using SSL certificates
    
* Discourse will be accessible directly through HTTPS on your domain
    
* All HTTP traffic will automatically redirect to HTTPS
    
* Check the logs if you encounter any issues: `/var/discourse/shared/standalone/log/rails/production.log`
    

After completing these steps, Discourse should be accessible via HTTPS through your domain, with Nginx handling all SSL termination\[1\]\[4\].

Citations: \[1\] [https://maker-tutorials.com/en/install-discourse-with-docker-in-subfolder-with-ssl-and-serve-other-content-under-the-same-domain/](https://maker-tutorials.com/en/install-discourse-with-docker-in-subfolder-with-ssl-and-serve-other-content-under-the-same-domain/) \[2\] [https://blog.khophi.co/install-run-discourse-behind-nginx-right-way-first-time/](https://blog.khophi.co/install-run-discourse-behind-nginx-right-way-first-time/) \[3\] [https://www.digitalocean.com/community/tutorials/how-to-install-discourse-behind-nginx-on-ubuntu-14-04](https://www.digitalocean.com/community/tutorials/how-to-install-discourse-behind-nginx-on-ubuntu-14-04) \[4\] [https://meta.discourse.org/t/installing-discourse-behind-reverse-proxy-using-recommended-supported-installation/300191](https://meta.discourse.org/t/installing-discourse-behind-reverse-proxy-using-recommended-supported-installation/300191) \[5\] [https://www.howtoforge.com/tutorial/how-to-install-and-configure-discourse-forum-with-nginx-on-ubuntu-1604/](https://www.howtoforge.com/tutorial/how-to-install-and-configure-discourse-forum-with-nginx-on-ubuntu-1604/)
