Skip to main content

How To Install HyperFastCgi On FreeBSD 12

Prerequisites FreeBSD 12. Mono. Mono-basic (optional). Libgdiplus. Nginx. Step 1 — Prepare Your Server Update Ports portsnap fetch update Install Git cd /usr/ports/devel/git/...

Prerequisites

FreeBSD 12.
Mono.
Mono-basic (optional).
Libgdiplus.
Nginx.

Step 1 — Prepare Your Server

Update Ports

portsnap fetch update

Install Git

cd /usr/ports/devel/git/
make install

Install GCC

Clang/LLVM is the system compiler on the several platforms in FreeBSD 12 and later, and GCC is not installed by default.

cd /usr/ports/lang/gcc8/
make config install clean

Add GCC alias

cd /usr/local/bin/gcc
ls - gcc*
gcc-ar8*     gcc-nm8*     gcc-ranlib8* gcc8*        
ln -s gcc8 gcc

Install Automake

cd /usr/ports/devel/automake/
make config install clean

Install libtool

cd /usr/ports/devel/libtool/
make install clean

Install libevent

cd /usr/ports/devel/libevent/
make config install clean

 

Step 2 — Install HyperFastCgi

git clone https://github.com/xplicit/HyperFastCgi.git
cd ./HyperFastCgi/
./autogen.sh --prefix=/usr/local
gmake
gmake install

Test HyperFastCgi

hyperfastcgi4 --version
HyperFastCgi.exe 0.4.4.0
(c) Sergey Zhukov

 

Step 3 — Configure HyperFastCgi

Move the simple configuration file ./HyperFastCgi/samples/server.config to /usr/local/etc/hyperfastcgi4/server.config and edit:

<configuration>
	<server type="HyperFastCgi.ApplicationServers.SimpleApplicationServer">
		<!-- Host factory defines how host will be created. SystemWebHostFactory creates host in AppDomain in standard ASP.NET way --> 
		<host-factory>HyperFastCgi.HostFactories.SystemWebHostFactory</host-factory>
		<!-- <threads> creates threads at startup. Value "0" means default value --> 
		<threads min-worker="40" max-worker="0" min-io="4" max-io="0" />
		<!--- Sets the application host root directory -->
		<!-- <root-dir>/usr/local/www/nginx</root-dir> -->
	</server>
	<listener type="HyperFastCgi.Listeners.NativeListener">
		<apphost-transport type="HyperFastCgi.Transports.NativeTransport">
			<multithreading>Single</multithreading>
		</apphost-transport>
	    <protocol>InterNetwork</protocol>
	    <address>127.0.0.1</address>
	    <port>9000</port>
	</listener>
    <apphost type="HyperFastCgi.AppHosts.AspNet.AspNetApplicationHost">
		<log level="Debug" write-to-console="true" />
		<add-trailing-slash>false</add-trailing-slash>
    </apphost>
    <web-applications>
    	<web-application>
    		<name>ApplicationServer</name>
    		<vhost>a1.domain.com</vhost>
    		<vport>443</vport>
    		<vpath>/</vpath>
    		<path>/usr/local/www/nginx/a1.domain.com</path>
    	</web-application>
    </web-applications>
</configuration>

Step 4 — Configure Nginx to Use HyperFastCgi

upstream fastcgi_backend {
  #server unix:/tmp/my-web-app.socket;
  server 127.0.0.1:9000;
  keepalive 32;
}

# HTTP server
server {
        listen   80;
        listen [::]:80;

        server_name  a1.domain.com www.a1.domain.com;
        access_log   /var/log/nginx/a1.domain.com.access.log;

        # Redirect to https
        rewrite ^ https://a1.domain.com$request_uri? permanent; #301-redirect
}


# HTTPS server
server {

        listen 443 ssl spdy;

        server_name  a1.domain.com www.a1.domain.com;
        access_log   /var/log/nginx/a1.domain.com.access.log;

	location / {
	    root /usr/local/www/nginx/a1.domain.com/;
	    index index.aspx;
	    fastcgi_index index.aspx;
	    fastcgi_keep_conn on;
	    fastcgi_pass fastcgi_backend;
	    include /usr/local/etc/nginx/fastcgi_params;
	}

	… (ssl options)

}

Step 5 — Run HyperFastCgi

Command line

hyperfastcgi4 /config=/path/to/server.config /loglevels=Standard /printlog

More details here.

System startup script (/usr/local/etc/rc.d)

#!/bin/sh

# PROVIDE: hyperfastcgi
# REQUIRE: LOGIN nginx
# KEYWORD: shutdown

. /etc/rc.subr

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/mono
name="hyperfastcgi4"
rcvar="${name}_enable"
command="/usr/local/bin/hyperfastcgi4"
procname="/usr/local/bin/mono"
config="/usr/local/etc/hyperfastcgi4/server.config"
logfile="/var/log/hyperfastcgi4.log"
#Specifies what log levels to log. It can be any of the following values, or multiple if comma separated: Debug, Notice, Warning, Error, Standard (Notice,Warning,Error), All (Debug,Standard)
loglevels=Standard
command_args="/config=${config} /logfile=${logfile} /loglevels=${loglevels} >> $logfile &"

load_rc_config $name
run_rc_command "$1"

Add the following line in the /etc/rc.conf:

hyperfastcgi4_enable="YES"

Appendix 1 Uninstall HyperFastCgi

cd ./HyperFastCgi/
gmake uninstall