【问题标题】:Configure multi site on nginx server through IP using Digital Ocean使用 Digital Ocean 通过 IP 在 nginx 服务器上配置多站点
【发布时间】:2018-10-15 00:00:41
【问题描述】:

问题:无法访问在一台 nginx 服务器下处理的两个网站,即<<ip-address>> & <<ip-address>>/web2

数字海洋上的配置:

  1. 1 滴 / Ubuntu 18 / LEMP
  2. 我在 CodeIgniter 框架中有两个测试 PHP 网站
  3. 第一个网站的文件夹配置:/var/www/html/web1/
  4. 第二个网站的文件夹配置:/var/www/html/web2/

两个站点的 Nginx Server Block 配置

web1.com

server {
        listen 80;
        root /var/www/html/web1;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name <<ip-address>>;

        location / {
                try_files $uri $uri/ /index.php;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

web2.com

server {
        listen 80;
        root /var/www/html/web2;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name <<ip-address>>/web2;

        location /web2/ {
                try_files $uri $uri/ /index.php;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

我对nginx服务器完全陌生,我是根据数字海洋下的一个社区提供的文档来做的。

请帮忙!

谢谢。

【问题讨论】:

  • 那么,问题是没有任何效果?你最终在两个网址上都在同一个网站上?你最终进入了 404 页面?
  • 是的,它不起作用。两个 URL 都应该访问不同的网站 目前,它试图从 web1 站点找到 web2 作为控制器,因此出错。
  • 你得到什么错误信息?

标签: php codeigniter nginx nginx-config


【解决方案1】:

您要做的不是 nginx 开箱即用的工作方式。经过大量的摆弄,最终可能会以这种方式工作,但我认为这不值得。

请看,nginx 配置要求 server_name 是 FQDN(完全限定域名)或 IP 地址,但不是带路径的完整 URL。 在您的情况下,对 ip-​​address/web2 的请求可能实际上与 web1 的配置匹配(因此指向您不存在的 /var/www/html/web1/web2/

解决此问题的最佳方法(假设您希望将两个站点保持在同一个 droplet 上):为每个站点获取一个 FQDN。它可能是您已经拥有的域的子域(即 web1.sharad.com 和 web2.sharad.com)...然后在每个 nginx 的配置文件上使用适当的服务器名称(web1.sharad.com 和 web2.sharad .com),使用 sudo nginx -t 检查拼写错误和错误,如果一切正常,使用 sudo systemctl restart nginx 重新启动 nginx

【讨论】:

    猜你喜欢
    • 2020-05-28
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    • 2018-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多