Is it possible to use Apache instead of nginx as the Web Server?


I am struggling with ERPNext installation since last week. Finally, I think I am in the final step.

When installer is trying to launch nginx, it throws an error because port 80 is used by Apache.

I tried by changing port in /etc/nginx/conf.d/default.conf file to 8080, but it is not taken into account.

Any help will be greatly appreciated.


Try reading here:


I have read that before posting, but the answer there was: “You can use apache in front of Default nginx of ErpNext. Just proxypass all your requests from apache to nginx”.

I cannot even start nginx… if I would be able to start nginx, I could do that. The problem is that the ERPNext installer tries to launch nginx and since nginx cannot be started, installer exists.


There can be several configuration files involved. Check the following:

  • /etc/nginx/nginx.conf
  • /etc/nginx/conf.d/default.conf (you already mentioned this one).
  • /etc/nginx/sites-enabled/* (may be empty)

I just completed 2 installations over the weekend, so it’s all pretty fresh in my mind. I didn’t have another web server (like Apache) previously installed, though.

It may be easier to shutdown Apache temporarily. Let ERPNext finish its installation. Then modify Nginx, change ports, and bring Apache back online.

ERPNext installation sometimes makes a lot of assumptions about what you do/don’t want.

1 Like

I don’t have sites-enabled folder. Host and port is only available in default.conf file.

I could do what you suggested, however, I cannot have Apache off line for long time so I need to be sure it it will work.

I changed port in default.conf and try to manually start nginx but it still tries to use port 80.

However, I think starting nginx is the last step in the ERPNext installation so I guess ERPNext files are already fully installed. Where are ERPNext pages installed so that I can configure Apache to point to that folder?



Sure it’s possible to use different components of the tech stack in general but that does mean it will be easy to swap. :slight_smile:
In this case you should change the nginx config file under frappe-bench folder to change the port there and then reload nginx

@bkm @brian_pond @mwai I have finally installed ERPNext with NGINX listening on port 8000, and I have Apache to proxy all requests.

That works, however, NGINX is showing 502 page instead of the ERPNext site.

This is the config file for NGINX that was created by bench:

upstream erpnext-frappe {
	server fail_timeout=0;

upstream erpnext-socketio-server {
	server fail_timeout=0;

# setup maps

# server blocks

server {
	listen 8000;

	root /opt/bench/erpnext/sites;


	add_header X-Frame-Options "SAMEORIGIN";

	location /assets {
		try_files $uri =404;

	location ~ ^/protected/(.*) {
		try_files /$1 =404;

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

		proxy_pass http://erpnext-socketio-server;

	location / {
		try_files /$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;
		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-frappe;

	# error pages
	error_page 502 /502.html;
	location /502.html {
		root /opt/bench/bench-repo/bench/config/templates;

	# 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
	gzip on;
	gzip_http_version 1.1;
	gzip_comp_level 5;
	gzip_min_length 256;
	gzip_proxied any;
	gzip_vary on;
		# text/html is always compressed by HttpGzipModule

The error logged in nginx log file is:

2019/03/27 20:13:06 [alert] 7845#7845: 1024 worker_connections are not enough
2019/03/27 20:13:06 [error] 7845#7845: *17498 recv() failed (104: Connection reset by peer) while reading response header from upstream, client:, server:, request: "GET / HTTP/1.0", upstream: "", host: ""

Any idea of what’s going on?

Thanks a lot.

Hello again, I have modified “Location /” setting to “try_files $uri $uri/ =404;” but I get this error now:

*23053 directory index of "/opt/bench/erpnext/sites/" is forbidden

At least, NGINX is trying to load the site, but now some permission is missing. What could it be?


Probably a good idea to look at the owner of that path. It may not have the correct ownership due to your manipulating the installation. It might be as simple as a ‘chown’ command to get it right.


That’s the point. The owner is bench user since whole installation was made using that user according to installation instructions.

What user should be used?

OK… in all of my installations, the /opt directory and all of its sub-directories are owned by ‘root’

Also there is no ‘bench’ directory in any of them (and I have many ERPNext servers in operation).

It almost appears as if you installed the ERPNext system into the /opt directory (which doesn’t make any sense because it is a root only directory).

Not sure how you got there… hopefully someone else can imagine a path that lead you here and offer some help.


I have followed these instructions.

so, how can I solve it? can I safely move the whole /opt/bench directory to /home/bench/some-other-directory?



I have finally get the site to be loaded, however, now this error is occuring several times:

2019/04/04 11:55:34 [crit] 28498#28498: accept4() failed (24: Too many open files)

The last reported message is:

2019/04/04 11:55:34 [error] 28498#28498: *16474 upstream timed out (110: Connection timed out) while reading response header from upstream, client:, server:, request: "GET /favicon.ico HTTP/1.1", upstream: "", host: "", referrer: ""

What may be wrong here?


I am not sure, but it looks like a request was made that was not specific enough and both web services were trying to deal with it at the same time.



I have found something interesting.

I have compared my nginx conf files with another server nginx conf files, where erpnext does work, and I made them almost the same. Only changed site name parameter.

With that, the site is being reached and shows the error I told you.

The interesting thing I found is that I have run “sudo netstat -plnt” command in the other server, and I discover that nginx is listening on port 80 and python (???) on port 8000.

In my case, port 80 is taken by Apache, so I cannot use it, so I have used 8000.

That way, nginx is listening on port 8000 and upstream erpnext-frappe also on port 8000. So I think server enters a infinite recursion. That might be why the “Too many files” error.

The question of million dollars is, what is the “python” process that is listening on port 8000 in the server where erpnext does work?

I think if I emulate the environment, I could solve this, for example, if I define

upstream erpnext-frappe {
    server fail_timeout=0;

in nginx conf file and leave nginx listening on port 8000.

So the problem is now to know what “python” process is and how can I start it in my server to start listening on port 8001.


I have finally done it!!

I did not want to fight against the current anymore. So I have set nginx to listen on port 8020 and then reboot the server.

That way, I allowed python to start listening on port 8000. In this case, both nginx and python were started.

The last step was to configure the proxy pass in Apache to be able to connect remotely without using the port and voilà… at last erp next is running.


1 Like

Congratulations. Persistence pays off. Do let us know if there is anything further to be tweaked as you get used to this mode of operation.