Skip to content

Instantly share code, notes, and snippets.

@mskian
Forked from mcnaveen/n8n docker command.md
Created April 27, 2023 06:33
Show Gist options
  • Save mskian/43004fa598b3892ea89e02657093cfa4 to your computer and use it in GitHub Desktop.
Save mskian/43004fa598b3892ea89e02657093cfa4 to your computer and use it in GitHub Desktop.
Docker Command to Run n8n on Docker Container with Static IP Address

Create Docker Network

docker network create --subnet=172.1.0.0/16 Network Name

Run Docker Container

docker run -d --net NETWORKNAME \
--ip STATICIP \
-it \
--name n8n  \
-p 5678:5678 \
-v ~/.n8n:/root/.n8n \
--restart always \
-e NODE_ENV="production" \
-e WEBHOOK_TUNNEL_URL="https://domain.com" \
n8nio/n8n
$ docker ps
$ docker stop n8n
$ docker rm n8n
$ docker pull n8nio/n8n:latest
$ docker run -d --net n8n --ip STATIC_IP -it --name n8n  -p 5678:5678 -v ~/.n8n:/root/.n8n --restart always -e NODE_ENV="production" -e WEBHOOK_TUNNEL_URL="https://domain.com" n8nio/n8n
server {

    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name SITEURL;

    # Redirect www to non-www
    if ($host = www.SITEURL) {
        return 301 https://SITEURL$request_uri;
    }

    # Redirect HTTP to HTTPS - Remove this if you are Not Configuring SSL for your Site
    if ($scheme = http) {
       return 301 https://$server_name$request_uri;
    }

    # rest of the server block
    access_log  /var/log/nginx/n8n-access.log;
    error_log   /var/log/nginx/n8n-error.log;

    location / {
        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;
        proxy_set_header Host $http_host;
        proxy_pass http://DOCKERINTERNAL-IP:5678;
        proxy_http_version 1.1;
        proxy_set_header Connection '';
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;
        proxy_hide_header X-powered-by;
    }

    client_max_body_size 70m;

    ssl_certificate /etc/letsencrypt/live/SITEURL/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/SITEURL/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
    add_header Strict-Transport-Security max-age=63072000;
    add_header X-XSS-Protection "1; mode=block";
    # add_header X-Frame-Options SAMEORIGIN;
    # add_header X-Content-Type-Options nosniff;

}
server {

    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name SITEURL;

    # Redirect HTTP to HTTPS - Remove this if you are Not Configuring SSL for your Site
    if ($scheme = http) {
       return 301 https://$server_name$request_uri;
   }

    access_log  /var/log/nginx/n8n-access.log;
    error_log   /var/log/nginx/n8n-error.log;

    location / {
        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;
        proxy_set_header Host $http_host;
        proxy_pass http://DOCKERINTERNAL-IP:5678;
        proxy_http_version 1.1;
        proxy_set_header Connection '';
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;
        proxy_hide_header X-powered-by;
    }

    client_max_body_size 70m;

    ssl_certificate /etc/letsencrypt/live/SITEURL/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/SITEURL/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
    add_header Strict-Transport-Security max-age=63072000;
    add_header X-XSS-Protection "1; mode=block";
    # add_header X-Frame-Options SAMEORIGIN;
    # add_header X-Content-Type-Options nosniff;

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment