如何在Nginx中使用子域和文件夹

时间:2015-12-13 09:34:34

标签: nginx subdomain

我想在Nginx中使用子域和文件夹,如下所示:

myexample.example.com/admin

因此,基本上所有指向此地址的流量都将定向到静态html文件。我没有成功地尝试以下方法:

server {

 index index.html index.htm;
 server_name myexample.example.com;

location /admin{
  root /home/user/apps/myapp/current/dist;
}


}

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

试试这个:

server {
 root /usr/share/nginx/www;
 index index.html index.htm;
 server_name myexample.example.com;
 error_log  /var/log/nginx/error.log  info;
 access_log  /var/log/nginx/access.log;

location /admin{
  try_files $uri $uri/index.html $uri.html /usr/share/nginx/www/admin.html =404;
  #Make sure this file exists by doing 'cat /usr/share/nginx/www/admin.html'
}

}