• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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