How VPS - How to use/setup VPS
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System BSD

Nginx Reverse Proxy and Golang Setup on FreeBSD

How VPS by How VPS
September 1, 2019
in BSD
0
0
SHARES
12
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Requirements
  2. Install Tools
  3. Download and Install Golang
  4. Setup Environment Variables
  5. Verify Installation
  6. Setup Martini
  7. Setup Nginx Reverse Proxy
  8. Want to contribute?


Requirements

  • Basic knowledge of UNIX.
  • FreeBSD x64 with Nginx installed.

Install Tools

You will need several programs that are not shipped with FreeBSD. Run the following command to install them:

pkg install nano wget git mercurial bzr

Download and Install Golang

Download golang by running the following set of commands:

cd /tmp
wget https://storage.googleapis.com/golang/go1.3.3.freebsd-amd64.tar.gz
tar -C /usr/local -xzf go1.3.3.freebsd-amd64.tar.gz

Setup Environment Variables

Create a variable called GOPATH (which will be the location for installed packages) and add it to your path:

mkdir ~/.gopkg
setenv GOPATH /root/.gopkg
set path = ($path /usr/local/go/bin /root/.gopkg/bin)

If you want to have the path set on boot, then run the following command to add it to your .cshrc:

echo "setenv GOPATH /root/.gopkg" >> ~/.cshrc
echo "set path = ($path /usr/local/go/bin /root/.gopkg/bin)" >> ~/.cshrc

Verify Installation

Run go in your terminal. If you are presented with a list of options, then the installation was successful. Run the following command to install a web framework called Martini:

go get github.com/go-martini/martini

If you don’t see any errors, then you may proceed to the next step.

Setup Martini

Create a file called server.go and populate it with the following lines of code:

package main

import "github.com/go-martini/martini"

func main() {
  m := martini.Classic()
  m.Get("/", func() string {
    return "Hello from Vultr VPS :)!"
  })
  m.Run()
}

When done, save and run go run server.go. Provided that you do not see any errors on your terminal, then you can proceed to the next step.

Setup Nginx Reverse Proxy

Configure Nginx to reverse proxy to the Martini server. In /usr/local/etc/nginx/nginx.conf look for location and replace its content within the curly brackets with the following:

expires 8d;
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_read_timeout 5m;
proxy_connect_timeout 5m;

proxy_cache_key sfs$request_uri$scheme;
proxy_pass http://127.0.0.1:3000;
proxy_redirect off;

One you have added that, save and run service nginx restart or service nginx onerestart, then run go run server.go. In your browser, enter http://0.0.0.0 (change the IP accordingly) and you will see a page that says:

Hello from Vultr VPS :)!

Congratulations, you have successfully setup an Nginx reverse proxy server with Golang + Martini.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
How VPS

How VPS

Related Posts

BSD

Installing Bolt CMS on FreeBSD 12

September 1, 2019
BSD

How to Install Flarum Forum on FreeBSD 12

September 1, 2019
BSD

Choosing an OS: CentOS, Ubuntu, Debian, FreeBSD, CoreOS, or Windows Server

September 1, 2019
Next Post

How to Install Vanilla Forum on FreeBSD 12

How to Install PyroCMS on FreeBSD 11

Setup XMPP Server With Prosody And FreeBSD

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us

  • 121 Followers
  • 87.2k Followers

Recommended

How to Install and Use Apache PredictionIO for Machine Learning on CentOS 7

3 years ago

Setup a Team Fortress 2 Server on Arch Linux

3 years ago

Setup a Symfony 3 Application on Linux

3 years ago

How to Install Monica on CentOS 7

3 years ago

Instagram

    Please install/update and activate JNews Instagram plugin.

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

Topics

Apache Web Server Bluehost Review 2019 Bluehost Review 2020 Bluehost Review 2021 Centmin Mod CentminMod centos install htop fsck htop install HTTP DoS attack Install Snort on an Ubuntu install Zabbix on CentOS install Zabbix on CentOS 7 Linux Commands linux guide linux install htop linux vps setup guide MariaDB MariaDB Error Mysql mysqld error optimize MariaDB optimize Mysql snort Ubuntu
No Result
View All Result

Highlights

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Webmin Reviews

Virtualmin Reviews

CentOS Web Panel Reviews

Ajenti Reviews

ISPConfig Reviews

Trending

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

by How VPS
February 25, 2022
0

I tried to update some extensions by use yum on centOs which I specified in Dockerfile. After...

How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020
Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

February 17, 2020
Webmin Reviews

Webmin Reviews

February 17, 2020
How VPS – How to use/setup VPS

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Visit our landing page to see all features & demos.
LEARN MORE »

Recent News

  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8 February 25, 2022
  • How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”? November 17, 2020
  • How to optimize Mysql or MariaDB November 3, 2020

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

[mc4wp_form]

© 2018 JNews - City News Magazine WordPress theme. All rights belong to their respective owners.
JNews is a top selling 2018 WordPress News, Blog, Newspaper & Magazine Theme.

No Result
View All Result
  • Home

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.