【问题标题】:nginx configuration. how to give different web sites different names?nginx配置。如何给不同的网站起不同的名字?
【发布时间】:2013-04-22 13:01:46
【问题描述】:
我有一个从 sites-enables/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 为例。
提前感谢您的帮助
杰尼亚·伊夫列夫
【问题讨论】:
标签:
configuration
nginx
webserver
【解决方案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 也是如此)。