john mangual
john mangual

Reputation: 8178

serving two websites with nginx

I want to run a simple nginx page that serves two pages. One from folder ~/A and one from ~/B

Each folder runs a copy of Python's SimpleHTTPServer in ports 1000 and 2000

Each file has a single file called index.html with text Hello World!

server {    

        listen 80;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location /   {
                root ~/A;
                proxy_pass http://localhost:1000;
        }

        location /B/ {
                root ~/B;
                proxy_pass http://localhost:2000;
        }

}

Unfortunately curl http://localhost/B/index.html returns a 404.

<head>
<title>Error response</title>
</head>
<body>
<h1>Error response</h1>
<p>Error code 404.
<p>Message: File not found.
<p>Error code explanation: 404 = Nothing matches the given URI.
</body>

What is wrong with my nginx conf file? Why can't it route properly?

Upvotes: 0

Views: 176

Answers (2)

apeipo
apeipo

Reputation: 11

you can open the nginx debug log and s.
i think this url will matches 'location \' and goto A.

Upvotes: 0

uzsolt
uzsolt

Reputation: 6027

I think you want use alias ~/B instead of root ~/B because your location /B/ will try ~/B/B. See alias and root documentations.

Upvotes: 1

Related Questions