简体   繁体   English

将 HTTP 重定向到 NGINX 中的 HTTPS,闪亮的服务器不工作

[英]Redirect HTTP to HTTPS in NGINX with shiny server not working

Here I am following this tutorial to set up a shiny server and redirect http to https via nginx.在这里,我按照教程设置一个闪亮的服务器并通过 nginx 将 http 重定向到 https。

I set my /etc/nginx/sites-available/example.com with the configurations below.我使用以下配置设置了我的/etc/nginx/sites-available/example.com I manage to access the shiny app myapp through https://example.com .我设法通过https://example.com访问闪亮的应用程序myapp This means nginx is correctly routing https://example.com to http://example.com:3838/myapp .这意味着 nginx 正确地将https://example.com路由到http://example.com:3838/myapp

The problem is that when I visit http://example.com nginx does not redirect me to https://example.com as it should.问题是,当我访问http://example.com 时, nginx 并没有像它应该的那样将我重定向到https://example.com

Any ideas why this it happening?任何想法为什么会这样?

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

server {
   listen 443 ssl;
   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;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_prefer_server_ciphers on;
   ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

   location / {
       proxy_pass http://my_server_ip:3838/myapp;
       proxy_redirect http://my_server_ip:3838/myapp/ https://$host/;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection $connection_upgrade;
       proxy_read_timeout 20d;
   }
}

I think the error is here.我认为错误就在这里。 On the one hand you should enter the address of the app, eg 127.0.0.1 and on the other hand you want to forward to the folder /myapp/.一方面,您应该输入应用程序的地址,例如 127.0.0.1,另一方面,您要转发到文件夹 /myapp/。 But this works different with Nginx.但这与 Nginx 不同。

Remove: /myapp from proxy_pass and proxy_redirect从 proxy_pass 和 proxy_redirect 中删除:/myapp

Link 关联

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM