Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/feed-rss2.php on line 8
Nginx Reverse Proxy and Golang Setup on FreeBSD – AKLWEB HOST LLC Support Center https://support.aklwebhost.com Fri, 27 Dec 2019 06:46:43 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.4 Nginx Reverse Proxy and Golang Setup on FreeBSD https://support.aklwebhost.com/knowledgebase/nginx-reverse-proxy-and-golang-setup-on-freebsd/ https://support.aklwebhost.com/knowledgebase/nginx-reverse-proxy-and-golang-setup-on-freebsd/#respond Fri, 27 Dec 2019 06:43:45 +0000 https://support.aklwebhost.com/?post_type=manual_kb&p=2856 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 AKLWEB Host 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 AKLWEB Host VPS :)!

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

]]>
https://support.aklwebhost.com/knowledgebase/nginx-reverse-proxy-and-golang-setup-on-freebsd/feed/ 0