-1

问题:无法访问在一台 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服务器完全陌生,我是根据数字海洋下社区提供的文档来做的。

请帮忙!

谢谢。

4

1 回答 1

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如果一切正常,请重新启动 nginxsudo systemctl restart nginx

于 2018-10-14T16:00:41.087 回答