How to locally run a Yesod web app via Nginx?

2019-07-27 10:33发布

On the Yesod site I have the following (excerpt):

staticFiles "assets/"

newtype App = App
    { appStatic :: Static
    }

instance Yesod App where
    approot = ApprootStatic "http://localhost:9000/yello"

main :: IO ()
main = do
    appStatic <- static "assets"
    warp 9000 $ App appStatic

So, I'm declaring that my little web application will be hosted at the prefix yello.

Now, I want to run this on Nginx ... but don't get the configuration right :(

I have the following nginx.conf:

daemon off;
events {
    worker_connections  1024;
}
http {
    server {
        listen       80;
        server_name  localhost;

        location /yello/ {
            proxy_pass http://localhost:9000/;
        }
        #location /assets {
        #    root /Users/nrm/Learning/Haskell/web/yesod/yello;
        #    expires max;
        #}
    }
}

My local source code is at /Users/nrm/Learning/Haskell/web/yesod/yello, so I first start yello and then run nginx:

At Terminal 1:

[/Users/nrm/Learning/Haskell/web/yesod/yello]
$ stack build
$ stack exec -- yello

At Terminal 2:

[/usr/local/etc/nginx]                                                             
$ nginx

Then at the browser, I enter localhost/yello and the result is

Not Found

/yelloyello/yello

and the URL in the address bar changed to http://localhost/yelloyello/yello.

What am i missing here?

Update0: Simplified nginx.conf according to https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite. Still does not work :(

Update1: With the following configurations it's working (note, no prefix in approot!):

staticFiles "assets/"

newtype App = App
    { appStatic :: Static
    }

instance Yesod App where
    approot = ApprootStatic "http://localhost:9000"

main :: IO ()
main = do
    appStatic <- static "assets"
    warp 9000 $ App appStatic

nginx.conf:

daemon off;
events {
    worker_connections  1024;
}
http {
    server {
        listen       80;
        server_name  localhost;
        location /yello/ {
            proxy_pass http://localhost:9000/;
        }
    }
}

At Terminal 1:

[/Users/nrm/Learning/Haskell/web/yesod/yello]
$ stack build
$ stack exec -- yello

At Terminal 2:

[/usr/local/etc/nginx]                                                             
$ nginx

Then at the browser, enter http://localhost/yello.

0条回答
登录 后发表回答