nginx配置。如何给不同的网站不同的名字?

时间:2013-04-28 22:51:40

标签: configuration nginx webserver

我有一个指向sites-enable / qooxdoo到/var/www/qooxdoo/nginx.conf的指针,其中包含以下内容:

server {
    listen   80; ## listen for ipv4; this line is default and implied


    root /var/www/qooxdoo;
    index index.html index.htm;

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

访问我需要做的网站:localhost / 那就是它。但是如何为该网站命名呢?

例如,localhost / site1的排序。

提前感谢您的帮助 jenia ivlev

1 个答案:

答案 0 :(得分:1)

取决于您想要实现的目标。考虑文件系统中的以下目录。

/var/www
  - site-1
  - site-2
  - ...
  - site-n

现在,如果像你已经完成的那样配置nginx,你可以使用URL中的简单目录。

server {
    listen 80;
    root /var/www;
    index index.html index.htm;
    server_name localhost;
}

请求http://localhost/site-1将返回文件/var/www/site-1/index.html的内容(site-2的内容与site-n相同)。

如果您想使用子域,可以执行以下操作。

server {
    listen 80;
    root /var/www/site-1;
    index index.html index.htm;
    server_name site-1.localhost;
}

server {
    listen 80;
    root /var/www/site-2;
    index index.html index.htm;
    server_name site-2.localhost;
}

server {
    listen 80;
    root /var/www/site-n;
    index index.html index.htm;
    server_name site-n.localhost;
}

请求http://site-1.localhost/将返回文件/var/www/site-1/index.html的内容(site-2的内容与site-n相同)。