Generate ssl-certificate and configure RStudio server? - rstudio

Actually i need to run rstudio server using https.
By default is http://server-ip:8787
I am following this file- (ssl- configuration)
https://s3.amazonaws.com/rstudio-server/rstudio-server-pro-0.98.507-admin-guide.pdf

You can set-up access to the RStudio server via a proxy. By doing that and setting up the Apache or Nginx web server to use SSL, you will have secure access to the RStudio server.

Here's an example of how you can both Shiny and RStudio running on the same domain using SSL and Nginx. If you use https://YOURDOMAIN/ it will run your shiny apps; https://YOURDOMAIN/rstudio to be able to edit the shiny apps directly from the browser!
Replace YOURDOMAIN with your server URL:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
#Server with proxy
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /etc/letsencrypt/live/YOURDOMAIN/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/YOURDOMAIN/privkey.pem;
server_name YOURDOMAIN;
location / {
proxy_pass http://localhost:3838;
proxy_redirect http://localhost:3838/ $scheme://$host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
}
location /rstudio/ {
rewrite ^/rstudio/(.*)$ /$1 break;
proxy_pass http://localhost:8787;
proxy_redirect http://localhost:8787/ $scheme://$host/rstudio/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
}
}

Unfortunately SSL is only available in the paid version.
See: https://www.rstudio.com/products/rstudio-server-pro/

Related

Nginx reverse proxy on SpringBoot redirect to /forums in nginx directory

I have a springboot application running on an Nginx server reverse proxy, inside of the nginx WWW root i have a forums directory i want to access via url/forums. So i am trying to setup a proxy for nginx so when someone goes to the website url/forums it will redirect to the nginx forums directory where i will have my PHP forums.
server {
listen 443 ssl; # Monitor port
server_name realmlands.com www.realmlands.com; # Domain name configuration, can be multiple
ssl_certificate /etc/letsencrypt/live/realmlands.com-0002/fullchain.pem; # Certificate address
ssl_certificate_key /etc/letsencrypt/live/realmlands.com-0002/privkey.pem; # Certificate address
# Fixed Writing
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
# Projects with reverse proxy configuration here
location /forums {
proxy_pass https://localhost:8080/forums;
# Fixed Writing
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
location / {
proxy_pass https://localhost:8443;
# Fixed Writing
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
But what happens when i go to url/forums it seems to redirect the browser to localhost/forums and shows the "This can't be reached".
How can i make it redirect to the nginx forums directory?

Tell lighttpd used protocol (HTTPS) when Nginx reverse proxy is in front

I have a Nginx reverse proxy redirecting to a lighttpd server in the same machine. This reverse proxy works on HTTPS so I want to tell to lighttpd that HTTPS is being used as protocol instead of HTTP. Here is my Nginx confuguration.
server {
server_name mydomain.com;
merge_slashes off;
rewrite ^(.*?)//+(.*?)$ $1/$2 permanent;
location / {
proxy_pass http://localhost:8088/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
# SSL settings
}
server {
if ($host = mydomain.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
}
The lighttpd server is running a python application that uses web.py module but the returned value by web.ctx.protocol still is HTTP when it should be HTTPS. It looks like lighttpd ignores the X-Forwarded-Proto header sent by Nginx.
What am I doing wrong? Is there any additional configuration to be done?
Thanks.
You have to configure lighttpd to trust headers from upstream. Use mod_extforward in lighttpd. See https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModExtForward
Better than your many headers above, both nginx and lighttpd (via mod_extforward) support RFC 7239 Forwarded header.
https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/
Use of the "Forwarded" header should be preferred.

Laravel Forge Nginx redirecting all subdomains to https://example.com

So I'm using Laravel Forge's built-in features to generate and integrate a LetsEncrypt certificate. But I'm having issues with getting my subdomains to work.
Whenever I try to go to www.example.com or https://www.example.com, it redirects me to https://example.com. The same happens when I try to add more subdomains, like foo.example.com redirects to https://example.com
I have my domain hosted with Namecheap and set it up as so:
This is my Nginx configuration file as generated by Forge:
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/before/*;
# FORGE CONFIG (DOT NOT REMOVE!)
include upstreams/example.com;
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/example.com/244866/server.crt;
ssl_certificate_key /etc/nginx/ssl/example.com/244866/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
charset utf-8;
access_log off;
error_log /var/log/nginx/example.com-error.log error;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/server/*;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://386082_app/;
proxy_redirect off;
# Handle Web Socket Connections
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/after/*;
This is the first time I'm using an Nginx server so I'm not sure how to change that. I've tried playing around with my settings in Namecheap DNS settings, and making sure my SSL is generated with all the subdomains, but I don't the the issue is anywhere but within the nginx configuration. Searching around didn't give me a solid solution as I don't want to ward too far away from the default configuration by Forge, yet still manage to this work my way.
Any and all help will be highly appreciated!
Thank you

Create multiple websocket server with one port number

I am using netty 4.0.20 I want to create different websocket servers on the same port using different urls
for example,
wss://localhost:1234/PathA
wss://localhost:1234/PathB
wss://localhost:1234/PathC
is that possible?
Yes, this is possible with using reverse proxying, which can be done with Nginx.
This will require one additional server in your setup.
First you have to setup each server to listen to a different port and then you need the front end server to listen to your desired public port (in your case, this is 1234).
So lets say you have the following servers
Nginx listening at 0.0.0.0:1234
Netty that serves /PathA and listens at 0.0.0.0:1235
Netty that serves /PathB and listens at 0.0.0.0:1236
Netty that serves /PathC and listens at 0.0.0.0:1237
Now what you have to do is write an Nginx configuration file that will upgrade the connection from HTTP to Websocket and then reverse proxy each path to its corresponding server. An example configuration file that could do the job for you is the following.
{
listen 1234;
server_name localhost;
location ~PathA/$ {
proxy_pass http://localhost:1235;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "upgrade";
}
location ~PathB/$ {
proxy_pass http://localhost:1236;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "upgrade";
}
location ~PathC/$ {
proxy_pass http://localhost:1237;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "upgrade";
}
}

Nginx/Django Admin POST https only

I've got an Nginx/Gunicorn/Django server deployed on a Centos 6 machine with only the SSL port (443) visible to the outside world. So unless the server is called with the https://, you won't get any response. If you call it with an http://domain:443, you'll merely get a 400 Bad Request message. Port 443 is the only way to hit the server.
I'm using Nginx to serve my static files (CSS, etc.) and all other requests are handled by Gunicorn, which is running Django at http://localhost:8000. So, navigating to https://domain.com works just fine, as do links within the admin site, but when I submit a form in the Django admin, the https is lost on the redirect and I'm sent to http://domain.com/request_uri which fails to reach the server. The POST action does work properly even so and the database is updated.
My configuration file is listed below. The location location / section is where I feel like the solution should be found. But it doesn't seem like the proxy_set_header X-* directives have any effect. Am I missing a module or something? I'm running nginx/1.0.15.
Everything I can find on the internet points to the X-Forwarded-Protocol https like it should do something, but I get no change. I'm also unable to get the debugging working on the remote server, though my next step may have to be compiling locally with debugging enabled to get some more clues. The last resort is to expose port 80 and redirect everything...but that requires some paperwork.
[http://pastebin.com/Rcg3p6vQ](My nginx configure arguments)
server {
listen 443 ssl;
ssl on;
ssl_certificate /path/to/cert.crt;
ssl_certificate_key /path/to/key.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
server_name example.com;
root /home/gunicorn/project/app;
access_log /home/gunicorn/logs/access.log;
error_log /home/gunicorn/logs/error.log debug;
location /static/ {
autoindex on;
root /home/gunicorn;
}
location / {
proxy_pass http://localhost:8000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Protocol https;
}
}
Haven't had time yet to understand exactly what these two lines do, but removing them solved my problems:
proxy_redirect off;
proxy_set_header Host $host;

Resources