Try ERPNext Buy Support Partners Foundation

Configuration for Nginx that on another server

I have a Nginx server that seats in front of ERPNext server on my private network.
I want a request from internet to my Nginx server will be passed to ERPNext server.
I ran bench setup nginx and but it seems the generated configurations are only use for a Nginx server that install on the same server with ERPNext.
An example:

location /502.html {
root /home/vgs/bench/bench/config/templates;
internal;
}

I don’t want install another Nginx server on my ERPNext server.
How can I have production Nginx configuration for a Nginx server that seats in front of ERPNext server and proxy to that ERPNext server?
Thank you.

Hi @lapphan,

if I understand you correctly, you want the first nginx (not the one on the ERPNext server) to act like a reverse proxy.

If you want to achieve this with an apache2 server, you need a2enmod proxy (and depending on the configuration related modules). Then, in the virtual host config, you will need something like

<Proxy *>
           Order deny,allow
           Allow from all
    </Proxy>

    ProxyPass / https://[erpnext_ip]/
    ProxyPassReverse / https://[erpnext_ip]/
    ProxyPreserveHost On
    ProxyAddHeaders Off

The same can be achieved with nginx, refer e.g. to https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

Hope this helps.

Thank you @lasalesi.
You understand me. I want my Nginx server acts as a reverse proxy.
But I don’t want to have another Nginx server on my ERPNext server and can use the generated configuration from command bench setup nginx. I know how to config proxy_pass.
How can I achieve that with only my first Nginx server?

Hi @lapphan,
that part I did not understand.

  • on your ERPNext server: the standard nginx (configured by bench). Provides ERPNext on a local address
  • on your separate nginx gateway server: configure the reverse proxy (configuration has to be done manually, this function does not exist in bench)

So you have two nginx servers, on on each server…

Can you share a working nginx reverse proxy on the fron nginx server. I did like this, I can access the server but lost static files (css and img)

Sorry, we only have running apache2 reverse proxies (see snippet above), but nginx should be roughly similar, I guess

location / {
    proxy_pass https://[erpnext_ip];
}

What have you got?

server {
	listen		443 ssl http2;
	server_name	example.domain;
	location / {
		proxy_pass			http://<erpnext-ip>;
		proxy_set_header	Host				$host;
		proxy_set_header	X-Forwarded-For		$proxy_add_x_forwarded_for;
		proxy_set_header	X-Forwarded-Proto	$scheme;
		proxy_http_version	1.1;
		proxy_set_header	Upgrade $http_upgrade;
		proxy_set_header	Connection "upgrade";
		proxy_set_header	X-Frappe-Site-Name example.domain;
		proxy_set_header	Origin $scheme://$http_host;
		proxy_set_header	Host $host;
	}
}

with this one, I can access the site but the css and images cannot be accessed