Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

Nginx - deploying static page

I have a web application deployed on an nginx with the server name example.com under the path var/www/app.

I added another directory, var/www/demo and it only contains a static .html page; is it possible to have it like example.com/demo?

I have already created a file in /etc/nginx/sites-enabled with the following content:

server {
    location /demo {
        root /var/www;
    } 
}

But it is not working, can someone help?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Read http://nginx.org/en/docs/http/ngx_http_core_module.html#root

server {

root /var/www/;

  location /app {
    index index.html;
  }

  location /demo {
     index index.html;
  }

}

Folder structure is

/var/www/app/
--- /var/www/app/index.html
/var/www/demo/
--- /var/www/demo/index.html
$# curl localhost/demo/
<html>
 it works
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...