Plesk 12.5 Nginx代理将SSL传递到不同端口上的Node应用程序

时间:2016-04-30 14:38:50

标签: nginx plesk

前言:尝试为Plesk安装JXCore的Node Extension,但我无法让它工作。给我一些错误,他们的支持不是回复电子邮件......

[IP ADDRESS] =真实IP,example.com =真实域

无论如何,我的nodejs应用程序启动并运行SSL证书。如果我转到https://example.com:3000,这是我用于Node的端口,可以正常工作。 SSL证书加载所有绿色,一切都很好。

我正在使用Plesk 12.5,并且已经安装了Nginx。 .conf文件位于/var/www/vhosts/[domain]/conf/nginx.conf。

在顶部它说:

#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

他们不是在开玩笑。对此文件进行任何更改都会立即覆盖。

以下是整个文件内容:

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";
}

我不会包含HTTP(非ssl)内容,因为它的信息相同。唯一的区别是端口为80,proxy_pass设置为7080。

你会在底部注意到它有:

include "/var/www/vhosts/system/example.com/conf/vhost_nginx.conf";

这是我在该文件中添加的内容:

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;

}

把它放在那里给了我一个:

nginx: [emerg] duplicate location "/"

我也尝试过使用Plesk"附加的nginx指令"在设置中,但我得到了同样的错误:

nginx:[emerg]重复的位置" /" 有任何想法吗?我即将抛弃Plesk并调查AWS或其他...... 我得出结论:a)你不能覆盖Plesk创建的Nginx confs,b)你不能直接更改conf文件。

所以基本上没有Plesk的proxy_pass是不可能的。

编辑:

还尝试使用Upstream方式,但是通过Plesk或通过vhost_nginx.conf将Upstream指令添加到管理界面会给我一个错误,说明" nginx:[emerg]指令此处不允许上游"

编辑#2: 阅读这篇文章Nginx to address Nodejs app,添加此处解释的内容无效。开始认为使用Plesk是不可能的。

ARG!没有Plesk的服务器上这么简单的任务!

1 个答案:

答案 0 :(得分:14)

经过两天的捣乱,这就是为我解决的问题。 在Plesk中,您将转到"附加nginx指令"在"托管选项"页。

这是我添加Nginx proxy_pass到我的节点应用程序。 没有必要编辑或更改任何.conf文件。

## Set the location routing.
location ~ / {

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;

    ##Use the domain.tld here.
    proxy_pass https://example.com:3000;
}