title: Plesk 12.5 Nginx proxy pass SSL to Node app on different port
body: <p>Preface: tried installing JXCore's Node Extension for Plesk, and I can't get it to work. Gives me some error, and their support is not answering emails......</p>
  
  <p>[IP ADDRESS] = real IP, example.com = real domain</p>
  
  <p>ANYWAY, I have my nodejs app up and running with an SSL Cert. Works fine if I go to <a href="https://example.com:3000" rel="noreferrer">https://example.com:3000</a>, which is the port I'm using for Node. SSL cert loads up all green, and everything works great.</p>
  
  <p>I'm using Plesk 12.5, and Nginx comes installed already. The .conf file is located at /var/www/vhosts/[domain]/conf/nginx.conf.</p>
  
  <p>At the top it says:</p>
  
  <pre><code>#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
  #SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.
  </code></pre>
  
  <p>And they aren't kidding. Making any changes to this file get's overwrote almost immediately.</p>
  
  <p>Here is the entire file contents:</p>
  
  <pre><code>server {
          listen [IP ADDRESS]:443 ssl;
  
      server_name example.com;
      server_name www.example.com;
      server_name ipv4.example.com;
  
      ssl_certificate             /usr/local/psa/var/certificates/cert-HREdQ9;
      ssl_certificate_key         /usr/local/psa/var/certificates/cert-HREdQ9;
      ssl_client_certificate      /usr/local/psa/var/certificates/cert-wpX6q1;
  
      client_max_body_size 128m;
  
      root "/var/www/vhosts/msgable.com/httpdocs";
      access_log "/var/www/vhosts/system/example.com/logs/proxy_access_ssl_log";
      error_log "/var/www/vhosts/system/example.com/logs/proxy_error_log";
  
      location / {
              proxy_pass https://[IP ADDRESS]:7081;
              proxy_set_header Host             $host;
              proxy_set_header X-Real-IP        $remote_addr;
              proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
              access_log off;
      }
  
      location @fallback {
              proxy_pass https://[IP ADDRESS]:7081;
              proxy_set_header Host             $host;
              proxy_set_header X-Real-IP        $remote_addr;
              proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
              access_log off;
      }
  
      location ~ ^/plesk-stat/ {
              proxy_pass https://[IP ADDRESS]:7081;
              proxy_set_header Host             $host;
              proxy_set_header X-Real-IP        $remote_addr;
              proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
              access_log off;
      }
      location ~ ^/(.*\.(ac3|avi|bmp|bz2|css|cue|dat|doc|docx|dts|eot|exe|flv|gif|gz|htm|html|ico|img|iso|jpeg|jpg|js|mkv|mp3|mp4|mpeg|mpg|ogg|pdf|png|ppt|pptx|qt|rar|rm|svg|swf|tar|tgz|ttf|txt|wav|woff|woff2|xls|xlsx|zip))$ {
              try_files $uri @fallback;
      }
  
      location ~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon) {
              proxy_pass https://74.208.65.63:7081;
              proxy_set_header Host             $host;
              proxy_set_header X-Real-IP        $remote_addr;
              proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
              access_log off;
      }
  
      location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
              alias /var/www/vhosts/example.com/web_users/$1/$2;
              fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
              fastcgi_param PATH_INFO $fastcgi_path_info;
              fastcgi_pass "unix:///var/www/vhosts/system/example.com/php-fpm.sock";
              include /etc/nginx/fastcgi.conf;
      }
  
      location ~ ^/~(.+?)(/.*)?$ {
              proxy_pass https://[IP ADDRESS]:7081;
              proxy_set_header Host             $host;
              proxy_set_header X-Real-IP        $remote_addr;
              proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
              access_log off;
      }
  
      location ~ \.php(/.*)?$ {
              fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
              fastcgi_param PATH_INFO $fastcgi_path_info;
              fastcgi_pass "unix:///var/www/vhosts/system/example.com/php-fpm.sock";
              include /etc/nginx/fastcgi.conf;
      }
  
      location ~ /$ {
              index index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml;
      }
  
      include "/var/www/vhosts/system/example.com/conf/vhost_nginx.conf";
  }
  </code></pre>
  
  <p>I won't include the HTTP (non-ssl) stuff, because it's the same info. Only difference being that the port is 80, and the proxy_pass is set to 7080.</p>
  
  <p>You'll notice at the bottom, that it has:</p>
  
  <pre><code>include "/var/www/vhosts/system/example.com/conf/vhost_nginx.conf";
  </code></pre>
  
  <p>This is what I put into that file:</p>
  
  <pre><code>location / {
      proxy_pass https://[IP ADDRESS]:3000;
      proxy_set_header Host             $host;
      proxy_set_header X-Real-IP        $remote_addr;
      proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
      access_log off;
  </code></pre>
  
  <p>}</p>
  
  <p>Putting that in there gives me a:</p>
  
  <pre><code>nginx: [emerg] duplicate location "/"
  </code></pre>
  
  <p>I also tried using Plesk's "Additional nginx directives" in the settings, but I get the same error:</p>
  
  <p>nginx: [emerg] duplicate location "/" 
  Any ideas? I'm about to dump Plesk and look into AWS or something....
  I've come to the conclusion that, a) you can NOT overwrite Nginx confs created by Plesk, b) you can NOT change the conf file directly.</p>
  
  <p>So basically proxy_pass with Plesk is impossible.</p>
  
  <p>Edit:</p>
  
  <p>Also tried doing it the Upstream way, but adding Upstream directives to the admin interface through Plesk, or through vhost_nginx.conf gives me an error saying "nginx: [emerg] directive Upstream is not allowed here".</p>
  
  <p>Edit#2:
  Read this post <a href="https://serverfault.com/questions/541268/nginx-to-address-nodejs-app">Nginx to address Nodejs app</a>, adding what was explained in here does nothing. Starting to think this isn't possible using Plesk.</p>
  
  <p>ARG! Such a simple task on a server without Plesk!</p>