How to setup a production and a development site next to each other

I’ve installed ERPNext a while ago with the “easy install” script, its in production mode.

For some testing purposes I would like to install a development version of ERPNext as well, next to the already existing production version.

If I’ve understood correctly I have to install another bench which in’t running in production, so I did:
bench init frappe-bench-dev && cd frappe-bench-dev
bench get-app erpnext https://github.com/frappe/erpnext
bench new-site erp-dev.domain.com
bench --site erp-dev.domain.com install-app erpnext

All fine so far.

I’ve also changed the hostname of the existing site from site1.local to erp.domain.com by:
bench setup add-domain --site site1.local erp.domain.com

Now erp.domain.com gives me the existing ERPNext site, but if I go to erp-dev.domain.com i get “Sorry! We will be back soon.”

What do I have to do be able to run the development site on erp-dev.domain.com next to the existing erp.domain.com, both on port 80 and both automatically started by supervisor?

2 Likes

I do this, but I have two separate bench instances frappe-bench-prd and frappe-bench-dev. Each bench has only one site in it erp.domain.com in frappe-bench-prd and then erp-dev.domain.com in frappe-bench-dev. That way all code bases are completely isolated from each other and you can update the dev instance at any time and do testing before you update prod.

That what I’m having at this moment. I’ve got two branches, each containing only one site. I can reach the production bench and site, which i installed with the easy install script, at erp.domain.com

The problem is that I can’t reach the development bench and site. I would like to reach them at erp-dev.domain.com, but I don’t know how to set up.

I suspect I have to add some configuration to Nginx and Supervisor?

I assume you have more than one ip address bound to the network adapter and then dns setup to point to proper ip by name? I have dev running on port 8080. I manually edited the nginx.conf file to do that, but I think there is a bench command to do it.

No, the machine has only one IP, the dns server has the two hosts (erp.domain.com and erp-dev.domain.com) pointing to that IP address. So normally I would have to setup virtual hosts to make this work.
The manual (https://github.com/frappe/bench/wiki/Multitenant-Setup) also speaks about multitenant based on dns instead of port, put I think those samples are based on a single bench setup with multiple sites and is not mentioning multiple benches.

what’s the benefit of

a) 2 benches serving 1 site (which apparently is what you 2 suggest here) over
b) 1 bench serving 2 sites

[disclaimer: no preference on that matter on my end at all, just curious]

The main thing is you cannot update only a single site at a time in one bench. So when you want a dev instance you need that in a different bench than prod site so you can update the dev bench first, do testing and then update the prod bench. With multi-tenant this is really important as you don’t want to update a ton of prod sites that have not been tested.

got it, thanks for clarifying. totally makes sense

Does anybody have an answer / solution for this?

I don’t know how to do apache httpd “like” virtual hosts by name with nginx and since nginx is running under two different benches, its running two different nginx.conf files and instances.

My recommendation is to manually edit the nginx.conf file and setup a redirect from port 80 to port 8080 and then have erp dev run on port 8080 on the same host.

Hi James,
Please could you give an example of your nginx.conf setup?
I’m trying to set this up, an no matter what I try I get the “Sorry! We will be back soon.” page on the dev bench.
Thanks!

Here you go. I just have dev listening on port 8080 and don’t worry about any kind of redirect.

server {
        listen 8080;
        server_name
                erpnext-dev
                ;

        root /home/erpnext/erpnext-dev/sites;

        location /assets {
                try_files $uri =404;
        }

        location ~ ^/protected/(.*) {
                internal;
                try_files /erpnext-dev/$1 =404;
        }

        location /socket.io {
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header X-Frappe-Site-Name erpnext-dev;
                proxy_set_header Origin $scheme://$http_host;
                proxy_set_header Host $host;

                proxy_pass http://erpnext-dev-socketio-server;
        }

        location / {
                try_files /erpnext-dev/public/$uri @webserver;
        }

        location @webserver {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Frappe-Site-Name erpnext-dev;
                proxy_set_header Host $host;
                proxy_set_header X-Use-X-Accel-Redirect True;
                proxy_read_timeout 120;
                proxy_redirect off;

                proxy_pass  http://erpnext-dev-frappe;
        }

        # error pages
        error_page 502 /502.html;
        location /502.html {
                root /home/erpnext/.bench/bench/config/templates;
                internal;
        }

        # optimizations
        sendfile on;
        keepalive_timeout 15;
        client_max_body_size 50m;
        client_body_buffer_size 16K;
        client_header_buffer_size 1k;

        # enable gzip compresion
        # based on https://mattstauffer.co/blog/enabling-gzip-on-nginx-servers-including-laravel-forge
        gzip on;
        gzip_http_version 1.1;
        gzip_comp_level 5;
        gzip_min_length 256;
        gzip_proxied any;
        gzip_vary on;
        gzip_types
                application/atom+xml
                application/javascript
                application/json
                application/rss+xml
                application/vnd.ms-fontobject
                application/x-font-ttf
                application/font-woff
                application/x-web-app-manifest+json
                application/xhtml+xml
                application/xml
                font/opentype
                image/svg+xml
                image/x-icon
                text/css
                text/plain
                text/x-component
                ;
                # text/html is always compressed by HttpGzipModule
}

Great, thank you!

Hi @nabinhait

Could you please give some guidance on this? I encountered the same issue but in my case, the second domain name just goes to the site in the first bench. How does a user point a domain to the correct bench when they have multiple benches setup on one machine?

Thanks

By the way, the domain name resolved correctly once I setup production but I’m not quite sure if this answers the question ‘how to setup domains for a production and development site on the same machine’

Thanks