• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Nginx subdomain vhost [SOLVED]

Praveen

New Pleskian
Hello
I am having trouble setting up the following configuration.

domain.com - nginx (reverse proxy) -> Apache ---- This works, no issues
myapp.domain.com - nginx (reverse proxy) -> Nodejs ---- This setup doesn't work.

Here are the things which I tried.

My app works as subfolder (by adding "location /myapp" and proxy directives in Plesk web server settings -> nginx directives )
domain.com/myapp - nginx (reverse proxy) -> Nodejs --- works

But I want it at the subdomain root level. So I created a subdomain in plesk and I tried the "location /" in nginx directive, but I am getting duplicate location.

So I deleted the subdomain and tried the server directive in /etc/nginx/conf.d/myapp.conf as follows,
Code:
server {
        listen 0.0.0.0:80;
        server_name myapp.domain.com;
        access_log /var/log/nginx/myapp.log;
        location / {
            proxy_pass http://127.0.0.1:38600/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_cache_bypass $http_upgrade;
        }
}
What I am getting is plesk default web page and not my app page. My subdomain DNS is also setup to point to main domain's ip address.

So how do I achieve this setup? Please help.
 
Hi Praveen,

without any specific root - folder definition, you always will be rooted to for example "/var/www/vhosts/default/htdocs". Please have a look at your default site - configuration, defined at "/etc/nginx/sites-enabled/*" to learn how your system is configured.
 
Thanks for the feedback. My nginx installation does not contain sites-enabled folder but it contains conf.d, so I added my subdomain conf in that folder as shown in the original post. Moreover is the root definition required? Because nginx has to just proxy the request (on a subdomain) to nodejs running on specific port in localhost.

I also tested with root set to my nodejs app folder but still getting the default domain page.
 
Last edited:
I got it to work. This line was causing the problem

access_log /var/log/nginx/myapp.log;

I missed double quotes for the path. o_O
 
Again the problem started showing up. I don't know what is causing the issue. Double quotes/no quotes does not make any difference.
 
Hi Praveen,

apache and nginx have both "configuration checker" included. Before you restart apache and/or nginx ( because you probably added configuration directives or modifications ), please always use the commands:

/usr/sbin/apachectl -t
Successfull configuration checks end with "Syntax OK"

or/and

/etc/init.d/nginx configtest
Successfull configuration checks end with:
Code:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

... to check your configuration(s). If you experience issues, please correct the mentioned parts from the output, or post your results here in the forums, so that people are able to help you with your investiations and possible solutions.


If you experience further issues, please include corresponding log - files and all possible configuration - files, so that people willing to help don't have to guess, when they try to help you.




Please have as well a look at:

... which already points to several solutions and ways, how you may find work-arounds for common issues. In addition, you will find usefull links, so that investigations are easier for you.
 
Back
Top