FAQ
I installed Ubuntu 12.04 LTS on my server and have full access to it.
Want to run a simple web server for a simple web page with images and
javascript.

My image files are installed under:
/BB/bb_public/public/images/
like this:
/BB/bb_public/public/images/logo.gif
...

My webServer:
/BB/bb_go/webServer/src/webServer.go
go build webServer.go

I run it like this:
sudo ./webServer

var webroot = flag.String("root", "/BB/bb_public/public", "web root
directory")
const listenAddr = "0.0.0.0:80"
...
http.Handle("/images/", http.StripPrefix("",
http.FileServer(http.Dir(*webroot))))
...
err := http.ListenAndServe(listenAddr, nil)
...

The web server is starting listening but I cannot see images, javascript
files cannot be loaded etc.
I am getting 404 messages like this:
[08:23:12.859] GET http://www.<my domain>.com/images/logo.gif [HTTP/1.1 404
Not Found 3ms]

Also - how can I run it as a service (like Windows service?)

--

Search Discussions

  • Peter at Jan 11, 2013 at 5:47 pm
    Could you try stripping the slash?

    http.Handle("/images/", http.StripPrefix(*"/"*,
    http.FileServer(http.Dir(*webroot))))
    On Friday, 11 January 2013 16:42:35 UTC, thstart wrote:

    I installed Ubuntu 12.04 LTS on my server and have full access to it.
    Want to run a simple web server for a simple web page with images and
    javascript.

    My image files are installed under:
    /BB/bb_public/public/images/
    like this:
    /BB/bb_public/public/images/logo.gif
    ...

    My webServer:
    /BB/bb_go/webServer/src/webServer.go
    go build webServer.go

    I run it like this:
    sudo ./webServer

    var webroot = flag.String("root", "/BB/bb_public/public", "web root
    directory")
    const listenAddr = "0.0.0.0:80"
    ...
    http.Handle("/images/", http.StripPrefix("",
    http.FileServer(http.Dir(*webroot))))
    ...
    err := http.ListenAndServe(listenAddr, nil)
    ...

    The web server is starting listening but I cannot see images, javascript
    files cannot be loaded etc.
    I am getting 404 messages like this:
    [08:23:12.859] GET http://www.<my domain>.com/images/logo.gif [HTTP/1.1
    404 Not Found 3ms]

    Also - how can I run it as a service (like Windows service?)
    --
  • Thstart at Jan 11, 2013 at 7:00 pm
    yes this worked - thank you!

    What Ubuntu server book is recommended?
    On Friday, January 11, 2013 9:47:03 AM UTC-8, Peter wrote:

    Could you try stripping the slash?

    http.Handle("/images/", http.StripPrefix(*"/"*,
    http.FileServer(http.Dir(*webroot))))
    On Friday, 11 January 2013 16:42:35 UTC, thstart wrote:

    I installed Ubuntu 12.04 LTS on my server and have full access to it.
    Want to run a simple web server for a simple web page with images and
    javascript.

    My image files are installed under:
    /BB/bb_public/public/images/
    like this:
    /BB/bb_public/public/images/logo.gif
    ...

    My webServer:
    /BB/bb_go/webServer/src/webServer.go
    go build webServer.go

    I run it like this:
    sudo ./webServer

    var webroot = flag.String("root", "/BB/bb_public/public", "web root
    directory")
    const listenAddr = "0.0.0.0:80"
    ...
    http.Handle("/images/", http.StripPrefix("",
    http.FileServer(http.Dir(*webroot))))
    ...
    err := http.ListenAndServe(listenAddr, nil)
    ...

    The web server is starting listening but I cannot see images, javascript
    files cannot be loaded etc.
    I am getting 404 messages like this:
    [08:23:12.859] GET http://www.<my domain>.com/images/logo.gif [HTTP/1.1
    404 Not Found 3ms]

    Also - how can I run it as a service (like Windows service?)
    --
  • Thstart at Jan 11, 2013 at 7:01 pm
    Also = how to make it run as a service?
    On Friday, January 11, 2013 9:47:03 AM UTC-8, Peter wrote:

    Could you try stripping the slash?

    http.Handle("/images/", http.StripPrefix(*"/"*,
    http.FileServer(http.Dir(*webroot))))
    On Friday, 11 January 2013 16:42:35 UTC, thstart wrote:

    I installed Ubuntu 12.04 LTS on my server and have full access to it.
    Want to run a simple web server for a simple web page with images and
    javascript.

    My image files are installed under:
    /BB/bb_public/public/images/
    like this:
    /BB/bb_public/public/images/logo.gif
    ...

    My webServer:
    /BB/bb_go/webServer/src/webServer.go
    go build webServer.go

    I run it like this:
    sudo ./webServer

    var webroot = flag.String("root", "/BB/bb_public/public", "web root
    directory")
    const listenAddr = "0.0.0.0:80"
    ...
    http.Handle("/images/", http.StripPrefix("",
    http.FileServer(http.Dir(*webroot))))
    ...
    err := http.ListenAndServe(listenAddr, nil)
    ...

    The web server is starting listening but I cannot see images, javascript
    files cannot be loaded etc.
    I am getting 404 messages like this:
    [08:23:12.859] GET http://www.<my domain>.com/images/logo.gif [HTTP/1.1
    404 Not Found 3ms]

    Also - how can I run it as a service (like Windows service?)
    --
  • Martin Schnabel at Jan 11, 2013 at 7:29 pm

    On 01/11/2013 05:42 PM, thstart wrote:

    I run it like this:
    sudo ./webServer
    be aware of the risks running your webserver as root.
    i would recommend using an nginx webserver in front of your go app
    instead. nginx is great for serving files, streaming media, is
    lightweight and has good defaults for keepalive and other timeouts.
    Also - how can I run it as a service (like Windows service?)
    on ubuntu i would probably use upstart.
    http://upstart.ubuntu.com/

    --
  • Thstart at Jan 11, 2013 at 7:46 pm
    This was a quick test to see if it works.

    Where there is more detailed info about using nginx + Golang?

    Thank you.
    On Friday, January 11, 2013 11:16:25 AM UTC-8, mb0 wrote:
    On 01/11/2013 05:42 PM, thstart wrote:

    I run it like this:
    sudo ./webServer
    be aware of the risks running your webserver as root.
    i would recommend using an nginx webserver in front of your go app
    instead. nginx is great for serving files, streaming media, is
    lightweight and has good defaults for keepalive and other timeouts.
    Also - how can I run it as a service (like Windows service?)
    on ubuntu i would probably use upstart.
    http://upstart.ubuntu.com/
    --
  • Minux at Jan 11, 2013 at 7:48 pm

    On Sat, Jan 12, 2013 at 3:45 AM, thstart wrote:

    Where there is more detailed info about using nginx + Golang?
    please search the mailing list archive.
    a recent post even gives a configuration file example.

    --
  • Voidlogic7 at Jan 11, 2013 at 8:15 pm
    Running your program as root is a horrible idea, one way to avoid it is to
    grant your binary the privilege to connect to low ports:

    user@users-prodbox:~/$ sudo aptitude install
    libcap2-bin
    user@users-prodbox:~/$ sudo setcap 'cap_net_bind_service=+ep'
    /usr/local/bin/goProgram
    www@users-prodbox:~/$ nohup goProgram &
    On Friday, January 11, 2013 1:16:25 PM UTC-6, mb0 wrote:
    On 01/11/2013 05:42 PM, thstart wrote:

    I run it like this:
    sudo ./webServer
    be aware of the risks running your webserver as root.
    i would recommend using an nginx webserver in front of your go app
    instead. nginx is great for serving files, streaming media, is
    lightweight and has good defaults for keepalive and other timeouts.
    Also - how can I run it as a service (like Windows service?)
    on ubuntu i would probably use upstart.
    http://upstart.ubuntu.com/
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 11, '13 at 4:42p
activeJan 11, '13 at 8:15p
posts8
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase