How to host a Happstack website?

好久不见. 提交于 2019-12-11 06:14:59

问题


I've built a website using Happstack, but I have no experience in hosting. Everything I found online was either outdated or too complex for me. Is there an easy way, or tutorial I can follow to publish my Happstack website?

Thanks


回答1:


Here's a short overview of the hosting process I followed to get a website running using Haskell server software.

Get a Server

The first thing you need when you're hosting is a device to run the server code.

You can either rent a "virtual computer" from a company (a Virtual Private Server or VPS) or you can use a computer you have lying about at home.

Virtual Private Server

Choose a VPS provider from among the huge number of companies that offer this kind of service. The provider should allow you to install software on the VPS and attach a static IP address to it. I have used AWS Lightsail and Cloud9 in the past.

Once you have decided on a provider you need to subscribe to a plan. What's important here is to pick an OS that you can install stack on. You should also choose enough RAM, storage space and clock speed to allow stack to work without problems.

When your VPS is ready for use attach a static IP address to it and then install stack on it.

If you're done with all this you can ignore the "Home Server" section and jump straight to "Set Up Happstack"

Home Server

Static IP (Home Network)

Have your home router assign a fixed IP to the device you intend to use as a server. Note that this only applies to your home network.

The way to make this work varies a lot across operating systems. You're better off running a web search for the steps specific to your OS.

Port Forwarding

Your home router's settings page should have a section called "Port Forwarding" or something similar.

The goal is to forward all connections made to port 80 of your home router to the port of your device that you have configured happstack to listen on. The IP address that you'll want to forward it to will be the fixed IP address of your device.

Again, the process varies quite a bit based on your router's manufacturer. You can always look up the steps to perform port forwarding on a router of a specific make and model.

Static IP (Internet)

Contact your internet service provider to get a fixed IP address for your router on the internet.

Set Up Happstack

Suppose you want to run happstack on port 81 of your device.

Perform the following steps:

  1. stack new happstack-hosting

  2. Add happstack-server to the list of dependencies inside the project's package.yaml file.

  3. Put the following code in the project's app/Main.hs file

    module Main where
    
    import Happstack.Server (nullConf, simpleHTTP, toResponse, ok, port)
    
    main :: IO ()
    main = simpleHTTP (nullConf { port = 81 }) $ ok "Hello, World!"
    
  4. Run stack build

  5. Run sudo stack exec happstack-hosting --allow-different-user

Of course, you'll have to substitute this Main.hs with your own server code once you've verified that you can access the website from the internet.

Use a Domain Name

Get a domain name from a registrar. I have used Google Domains, Namecheap and GoDaddy before but there are a lot of others out there.

If you're using a VPS follow your registrar's instructions to redirect the domain name to port 81 of your VPS's IP address.

Otherwise redirect the domain name to port 80 of your router's static IP address.




回答2:


Thanks for everyone who answered. I ended up using a docker image alongside heroku for deployment. If you want to see how the docker file looks check https://github.com/hpbl/haskellkoans



来源:https://stackoverflow.com/questions/51064865/how-to-host-a-happstack-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!