【问题标题】:How to configure NGINX properly for 2 different sites?如何为 2 个不同的站点正确配置 NGINX?
【发布时间】:2019-07-16 08:47:20
【问题描述】:

我正在设置新服务器,一切都完成了。第一个站点可以正常运行。

路径是:

/var/www/html

第二个站点仍然不可用,但是当我从命令行 ping 时,它说它在线。

多个目录应如下所示:

/var/www/html/1 

/var/www/html/2

还是别的什么?

此时我的 default.conf 来自:

/etc/nginx/sites-enabled

看起来像:

server {
listen 80;
server_name example.com;
root /var/www/html;
index index.html;
}

如果我想放置多个站点,我必须使这个文件看起来像:

server {
listen 80;
server_name example1.com;
root /var/www/html/1;
index index.html;
}
server {
listen 80;
server_name example2.com;
root /var/www/html/2;
index index.html;
}

还是?

有什么想法吗?

【问题讨论】:

  • 那么server_name是一样的吗? test.jasonrigden.com 在这两种配置中。所以只需要一个。
  • 你试过你的 conf 例子吗?发生了什么?
  • @Don'tPanic 老实说不是,我正在工作并试图弄清楚它是否有效。待我在家时会检查它。
  • @flaixman 不,server_name 不同。我已经改过了。

标签: nginx hosts multiple-sites


【解决方案1】:

我假设您使用基于 debian 的系统,例如 debian 或 ubuntu。

我建议将example2.com.conf 之类的文件添加到/etc/nginx/sites-available/ 并将其链接到/etc/nginx/sites-enabled/

例如

example2.com.conf:

server {
listen 80;
server_name example2.com;
root /var/www/html/2;
index index.html;
}

ln -s /etc/nginx/sites-available/example2.com.conf /etc/nginx/sites-enabled/ systemctl restart nginx

此页面上描述了更多详细信息。

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04#server-configuration

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    • 2022-11-27
    • 2013-08-29
    • 1970-01-01
    相关资源
    最近更新 更多