【问题标题】:Plesk 12.5 Nginx proxy pass SSL to Node app on different portPlesk 12.5 Nginx 代理将 SSL 传递到不同端口上的节点应用程序
【发布时间】:2016-08-25 16:04:13
【问题描述】:

前言:尝试为 Plesk 安装 JXCore 的节点扩展,但无法正常工作。给我一些错误,他们的支持是不回复电子邮件......

[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] 指令 Upstream is not allowed here”。

编辑#2: 阅读这篇文章Nginx to address Nodejs app,添加这里解释的内容没有任何作用。开始认为使用 Plesk 无法做到这一点。

啊!在没有 Plesk 的服务器上完成如此简单的任务!

【问题讨论】:

    标签: nginx plesk


    【解决方案1】:

    经过两天的折腾,这就是为我解决的问题。 在 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;
    }
    

    【讨论】:

    • 我认为这个答案的重要部分(对于我遇到的同样的问题)是使用“位置〜/”而不是“位置/”来避免重复警告。
    • 你说得对,我会删除所有其他不需要的东西。
    • 非常感谢!用location ~ / {} 包裹proxy_pass 解决了这个问题!
    • @mniess 查看here,看起来Onyx 必须是location / {} 和12.5 location ~^ {}
    • @gmo 你是对的。使用 Onyx,您可以只使用 / (就像最初的计划一样)。不过,似乎有一个小错误。在第一次保存时,您必须使用 / 以外的东西(例如 ~/),否则它会发出重复警告。保存后,您可以删除 ~ 并使用 /。
    猜你喜欢
    • 2021-05-29
    • 2012-05-09
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 2021-02-04
    • 2023-04-08
    相关资源
    最近更新 更多