Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using an Ubuntu web server with Plesk 11.5.x. I've added Nodejs and now i want to adress the Nodejs app with a subdomain.

Website: domain.tld

Nodejs App: app.domain.tld

Currently working: domain.tld:2368, but i want to hide the port with the help of a subdomain.


I should be able to do the following:

upstream app_myApp {
    server 127.0.0.1:2368;
}

server {
    listen 0.0.0.0:80;
    server_name app.domain.tld;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://app_myApp/;
      proxy_redirect off;
    }
 }

My problem is where to place this, because i am using Plesk. In Plesk 11.5's .../system/domain.tld/conf/vhost_nginx.conf are upstream and server commands not allowed. And location / isn't possible either.


I guess I would need something like /etc/nginx/sites-available/domain.tld. I have no idea where to add this without breaking plesk or my config being overwritten on an automatic plesk reconfig.

Any ideas?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can edit nginx template file

mkdir /usr/local/psa/admin/conf/templates/custom/domain
cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain 

in new file /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php find following lines:

    location / {
<?php echo $VAR->includeTemplate('domain/service/proxy.php', $OPT); ?>
    }

and adjust it to Your needs:

    location / {
<?php if ('mydomain.tld' == $VAR->domain->asciiName ) {
         echo $VAR->includeTemplate('PATHTONODECONFIG.php', $OPT); ?>
       } else {
         echo $VAR->includeTemplate('domain/service/proxy.php', $OPT); ?>
     }

I suggest to parametrise this condition, to be more flexible

share|improve this answer
    
does a plesk update overwrite the nginxDomainVirtualHost.php file? –  Asto Sep 25 '13 at 13:19
    
yes, you are right. it wil override these changes with new version. you should put custom template in this folder /usr/local/psa/admin/conf/templates/custom/domain/ i will fix manual too –  sergres Sep 27 '13 at 6:14
    
thank you - does nginx use automatically the custom template afterwards? what would i have to put in the nodeconfig file. i assume sth like "proxy_pass mydomain.tld:2368;"; or "proxy_pass 127.0.0.1:2368;"; in my case - but that didn't work –  Asto Sep 30 '13 at 17:43
    
Worked now with proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass 127.0.0.1:2368; proxy_redirect off; –  Asto Oct 9 '13 at 9:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.