简体   繁体   English

如何将Shiny App的http地址替换为https

[英]How to replace http address to https for Shiny App

I have a Shiny app hosted in Digitalocean with Web-server as Nginx . 我有一个Shiny应用程序托管在Digitalocean中 ,网络服务器为Nginx The Web-address looks like 网址看起来像

http://www.exacmple.com/ShinyApp http://www.exacmple.com/ShinyApp

However I wish if I could change the http to https. 但是,我希望是否可以将http更改为https。 ie all request to this App would be routed to https:/ /www.exacmple.com/ShinyApp 即对此应用程序的所有请求将被路由到https: ///www.exacmple.com/ShinyApp

I already have SSL certificate installed from letsencrypt , and certificate file is placed at below addresses: 我已经从letsencrypt安装了SSL证书,并且证书文件位于以下地址:

/etc/letsencrypt/live/example.com/fullchain.pem;
/etc/letsencrypt/live/example.com/privkey.pem;

Currently, my Nginx Proxy file is set like below: 目前,我的Nginx代理文件设置如下:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
  map $http_upgrade $connection_upgrade {
      default upgrade;
      ''      close;
    }



server {
    listen 80 default_server;
    listen [::]:80 default_server;
        server_name example.com www.example.com;
    if ($http_host = example.com) {
            rewrite  (.*)  https://www.example.com$1;
          }



    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

location /ShinyApp/ {
      rewrite ^/ShinyApp/(.*)$ /$1 break;
      proxy_pass http://localhost:4242;    
      proxy_redirect http://localhost:4242/ $scheme://$host/ShinyApp/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_read_timeout 20d;
      proxy_buffering off;
    }
}

To implement for https , I have appended this file as below (the location section ) 为了实现https ,我将这个文件添加如下( 位置部分

location /ShinyApp/ {
      rewrite ^/ShinyApp/(.*)$ /$1 break;
      SSLEngine on
      ssl_certificate           /etc/letsencrypt/live/example.com/fullchain.pem;
       ssl_certificate_key       /etc/letsencrypt/live/example.com/privkey.pem;

      ProxyPreserveHost On
      proxy_pass http://localhost:4242;
      roxyPassReverse http://localhost:4242;
      proxy_redirect http://localhost:4242/ $scheme://$host/ShinyApp/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_read_timeout 20d;
      proxy_buffering off;
    }

However above change fails to implement https request. 但是上述更改无法实现https请求。

I have gone through various suggestions available over Web (eg HTTPS for Shiny apps? ) however failed to find any workable solution. 我已经浏览了Web上的各种建议(例如, 适用于Shiny应用程序的HTTPS? ),但是找不到任何可行的解决方案。

Any pointer towards the right direction would be very helpful. 任何指向正确方向的指针都将非常有帮助。

Thanks, 谢谢,

Common practice for this is to use two server blocks: 常见的做法是使用两个服务器块:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name example.com www.example.com;
    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ... # root, index and other top-level directives here
    location /ShinyApp/ {
        # your backend configuration here
    }
}

Don't use ssl_certificate and ssl_certificate_key directives inside a location blocks, pay attention on a context in which nginx directives may or may not be used. 不要在location块内使用ssl_certificatessl_certificate_key指令,请注意可能使用或可能不使用nginx指令的上下文。 SSLEngine , ProxyPreserveHost and ProxyPassReverse are apache directives, remove them! SSLEngineProxyPreserveHostProxyPassReverse是apache指令,请将其删除! Test your configuration with nginx -t before reloading nginx with a new configuration. 在使用新配置重新加载nginx之前,请先使用nginx -t测试您的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在URL中用HTTP替换HTTPS? - How can I replace HTTPS with HTTP in a URL? 如何将 HTTP 替换为 HTTPS 以实现页面安全 - How to Replace HTTP to HTTPS for page secure 如何将带有 IP 地址的 HTTP URL 重定向到带有域名的 HTTPS URL? - How to redirect HTTP URL with IP address to HTTPS URL with domain name? 如何使用Greasemonkey将http链接替换为整页中的https? - How to replace http links to https in whole page using Greasemonkey? 如何将Bluemix上的Python应用程序上的HTTP请求重定向到仅HTTPS? - How to redirect HTTP requests on a Python App on Bluemix to HTTPS only? 如何测试我的应用程序是否可以连接 https 并回退到 http 否则? - How to test if my app can connect with https and fallback to http otherwise? 如何将http重定向到https - How redirect http to https 如何将https更改为http - How to change https to http Java Reguar 表达式:如何用一个斜杠替换双斜杠或多个斜杠但忽略 http:// 或 https:// - Java Reguar Expression: How to replace double or more slashes with a single slash but ignoring http:// or https:// 错误:闪亮的应用程序中的[_parse_http_data]无效的HTTP方法 - ERROR: [_parse_http_data] invalid HTTP method in shiny app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM