【问题标题】:I Have two Websites which i want to run from one ip with Nginx我有两个网站,我想用 Nginx 从一个 ip 运行
【发布时间】:2020-06-16 00:58:06
【问题描述】:

下面是我的配置文件

server {
     listen 80 default_server;

   server_name _;
root /var/www/html;


   index index.html index.htm;

    location /test1/ {
       alias  /var/www/html/test1;
            try_files $uri  /index.html;}

  location /test2/ {
      alias /var/www/html/test2;
       try_files $uri /index.html;}}

如果有人帮我解决这个问题 为此,我在网络浏览器中收到 404 错误。

【问题讨论】:

  • 两个独立的网站,还是一个有两个子文件夹的网站? site.com/test1/ & dite.com/test2/ ?
  • 一个 ip 和两个网站,如localhost/test1 & localhost/test2

标签: linux nginx


【解决方案1】:

对于两个单独的网站,如 site1.com 和 site2.com,您需要在其自己的 server{} 块中指定两个单独的 server_name 指令:

server {
   listen 80;
   server_name site1.com;
   root /var/www/html/site1;

   index index.html index.htm;
}

server {
   listen 80;
   server_name site2.com;
   root /var/www/html/site2;

   index index.html index.htm;
}

对于具有两个文件夹的单个主机,例如:

server {
   listen 80;
   server_name site1.com;
   root /var/www/html/site1;

   index index.html index.htm;

// here without specifying `root` it will use relative to
// the more general root above, so: /var/www/html/site1/folder1/

 location ~ /folder1 {
   index index.html index.htm;
}

// or you can specify `root` within the `location`,
// so it will load index from: /var/www/html/site1/folder2

 location ~ /folder1 {
   root /var/www/html/site1/folder2;
   index index.html index.htm;
}



}

【讨论】:

  • 在网络浏览器中出现同样的错误...虽然在我的 nginx error.log 中显示 /var/www/html/test1/test2/index.html" is not found (2: No such file or directory) this
  • 我的配置中没有test1test2,你从哪里得到的?
  • 它们在我的配置中...我使用一个 ip 和两个不同的子文件夹/网站。
  • 我之前问过。子文件夹不是网站......所以如果你有所有这些,你会得到错误。
猜你喜欢
  • 1970-01-01
  • 2019-06-23
  • 2011-11-27
  • 2023-04-10
  • 1970-01-01
  • 2013-12-19
  • 2015-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多