Custom HTTPD configuration not working on Apache/Nginx combination

ericovk

Verified User
Joined
Apr 17, 2012
Messages
228
Location
Rotterdam, Netherlands
We are running a Apache/Nginx combination pretty much out of the box. When I try to install Magento 2, I have to rename the public_html folder to pub. Therefore I added this rule to the "Custom4" field in HTTPD customizations at the admin level.
Code:
DocumentRoot /home/username/domains/domain.com/pub

DA says the syntax is okay, but on restart of Nginx, it won't start due to a misconfiguration.

Code:
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2017-04-20 14:06:29 CEST; 4s ago
  Process: 2004 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)


Apr 20 14:06:29 servername systemd[1]: Starting The nginx HTTP and reverse proxy server...
Apr 20 14:06:29 servername nginx[2004]: nginx: [emerg] unexpected "}" in /usr/local/directadmin/data/users/username/nginx.conf:39
Apr 20 14:06:29 servername nginx[2004]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 20 14:06:29 servername systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 20 14:06:29 servername systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Apr 20 14:06:29 servername systemd[1]: Unit nginx.service entered failed state.
Apr 20 14:06:29 servername systemd[1]: nginx.service failed.

After commenting the DocumentRoot rules manually, Nginx starts, but of course the changes I made are gone.

How can I set up this DocumentRoot folder properly at /pub in stead of /public_html?
 
Thanks, but it isn't working on this server. It still loads the public_html folder in stead.

I tried it with a hardcoded path, but it still lacks working.
Code:
|?DOCROOT=/home/mag2/domains/mag2.domain.com/pub|

edit: I tried this on my other server with Apache only, and over there it worked as expected. But only on the Apache / Nginx combo the server just isn't willing to load another folder.
 
Last edited:
Are you sure that you added the line into both NGINX and Apache?
Did you make sure that NGINX and Apache restarted?

Code:
killall -9 nginx
killall -9 httpd

and then start nginx/apache.

How are your configs in nginx and apache for the domain looking like?
 
The only thing I added was your piece of code at custom1
Code:
|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html/sub|


I can't find any trails for an error for this strange behaviour. Searched my error logs, but I only found this:
Code:
tail /var/log/httpd/error_log
[Tue Apr 25 07:53:30.011882 2017] [mpm_event:notice] [pid 22837:tid 140257394391168] AH00492: caught SIGWINCH, shutting down gracefully
[Tue Apr 25 07:55:14.248289 2017] [ssl:warn] [pid 1200:tid 140714591922304] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Tue Apr 25 07:55:14.249590 2017] [ssl:warn] [pid 1200:tid 140714591922304] AH01909: www.example.com:8081:0 server certificate does NOT include an ID which matches the server name
[Tue Apr 25 07:55:14.249752 2017] [suexec:notice] [pid 1200:tid 140714591922304] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Apr 25 07:55:14.284503 2017] [auth_digest:notice] [pid 1200:tid 140714591922304] AH01757: generating secret for digest authentication ...
[Tue Apr 25 07:55:15.016453 2017] [ssl:warn] [pid 1200:tid 140714591922304] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Tue Apr 25 07:55:15.017131 2017] [ssl:warn] [pid 1200:tid 140714591922304] AH01909: www.example.com:8081:0 server certificate does NOT include an ID which matches the server name
[Tue Apr 25 07:55:15.017293 2017] [lbmethod_heartbeat:notice] [pid 1200:tid 140714591922304] AH02282: No slotmem from mod_heartmonitor
[Tue Apr 25 07:55:15.021970 2017] [mpm_event:notice] [pid 1200:tid 140714591922304] AH00489: Apache/2.4.25 (Unix) OpenSSL/1.0.1e-fips configured -- resuming normal operations
[Tue Apr 25 07:55:15.022021 2017] [core:notice] [pid 1200:tid 140714591922304] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'


Seems okay to me. Besides that I don't know why the server is giving me error notices on localhost:443 because the server has a valid Letsencrypt SSL certificate.


The content of the HTTPD config looks like this:


Contents of the httpd.conf file for magento2.domain.com
Code:
# Auto generated nginx config file by DirectAdmin version 1.51.3
# Modifying this file is not recommended as any changes you make will be
# overwritten when the user makes any changes to their website


# For global config changes that affect all Users, see this guide:
# http://help.directadmin.com/item.php?id=558
# For local config changes that only affect one User, see this guide:
# http://help.directadmin.com/item.php?id=3




server
{
	listen 46.145.192.200:80;
	server_name magento2.domain.com www.magento2.domain.com ;
	access_log /var/log/nginx/domains/magento2.domain.com.log;
	access_log /var/log/nginx/domains/magento2.domain.com.bytes bytes;
	error_log /var/log/nginx/domains/magento2.domain.com.error.log;
	root /home/mag2/domains/magento2.domain.com/public_html/pub;
	index index.php index.html index.htm;
	include /usr/local/directadmin/data/users/mag2/nginx_php.conf;
	location /
	{
		# access_log off;
		proxy_buffering off;
		proxy_pass http://46.145.192.200:8080;
		proxy_set_header X-Client-IP      $remote_addr;
		proxy_set_header X-Accel-Internal /nginx_static_files;
		proxy_set_header Host             $host;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
	}
	location /nginx_static_files/
	{
		# access_log  /var/log/nginx/access_log_proxy;
		alias       /home/mag2/domains/magento2.domain.com/public_html/pub/;
		internal;
	}
	include /etc/nginx/webapps.conf;
}


server
{
	listen 46.145.192.200:443 ssl;
	server_name magento2.domain.com www.magento2.domain.com ;
	access_log /var/log/nginx/domains/magento2.domain.com.log;
	access_log /var/log/nginx/domains/magento2.domain.com.bytes bytes;
	error_log /var/log/nginx/domains/magento2.domain.com.error.log;
	root /home/mag2/domains/magento2.domain.com/public_html/pub;
	index index.php index.html index.htm;
	ssl on;
	ssl_certificate /etc/httpd/conf/ssl.crt/server.crt.combined;
	ssl_certificate_key /etc/httpd/conf/ssl.key/server.key;
	include /usr/local/directadmin/data/users/mag2/nginx_php.conf;
	location /
	{
		# access_log off;
		proxy_buffering off;
		proxy_pass https://46.145.192.200:8081;
		proxy_set_header X-Client-IP      $remote_addr;
		proxy_set_header X-Accel-Internal /nginx_static_files;
		proxy_set_header Host             $host;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
	}
	location /nginx_static_files/
	{
		# access_log  /var/log/nginx/access_log_proxy;
		alias       /home/mag2/domains/magento2.domain.com/public_html/pub/;
		internal;
	}
	include /etc/nginx/webapps.ssl.conf;
}

Configuration Check
Code:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


Everything looks ok, but the public_html is still the folder that's being loaded in stead of the pub folder.
 
Last edited:
You posted content only from NGINX. What about Apache? You run NGINX+Apache and should update config for the domain in both NGINX and Apache.

Are you sure that you added the line into both NGINX and Apache?
 
Aha! That was the trick. I expected DA to handle this automatically. After adding the same rule under both customization (and restarted Nginx and HTTPD) everything works as expected. Great! Thanks again Alex!
 
Back
Top