Set Application Domain Name with Shiny Server

Guest post by AVNER KANTOR

I used the wonderful tutorial of Dean Attall to set my machine in Google cloud. After I finished to configure it successfully I wanted to redirect my domain to the Shiny application URL. This is a short description how you can do it.

The first step is changing the domain server to your server supplier. You can find here a guide for several suppliers how to do it. I used Godaddy and Google Cloud DNS:

  • ns-cloud-b1.googledomains.com
  • ns-cloud-b2.googledomains.com
  • ns-cloud-b3.googledomains.com
  • ns-cloud-b4.googledomains.com

The tricky part is the setting up Nginx virtual hosts. The DigitalOcean tutorial helped me again.

We will create virtual hosts in etc/nginx/sites-available. In this directory you can find the default file you created when you set the environment (here is my file). Now you should add config file named after you domain name. Let’s assume it is example.com. Here is the config file you should have:

$ sudo nano /etc/nginx/sites-available/example.com
server {
  listen 80;
  listen [::]:80;
  root /var/www/html;

  server_name example.com www.example.com;

  location / {
    proxy_pass http://127.0.0.1:3838/example/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

It’s important to check that default_server option is only enabled in a single active file – in our case: deafult. You can do it by grep -R default_server /etc/nginx/sites-enabled/.

In order to enable the server block we will create symbolic links from these files to the sites-enabled directory, which Nginx reads from during startup.

$ sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

If no problems were found, restart Nginx to enable your changes:

sudo systemctl restart nginx

Now that you are all set up, you should test that your server blocks are functioning correctly. You can do that by visiting the domains in your web browser: http://example.com.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.