【问题标题】:Nginx page displaying instead of home page (Digital Ocean - LEMP)Nginx 页面显示而不是主页(Digital Ocean - LEMP)
【发布时间】:2022-02-22 14:54:56
【问题描述】:

我最近购买了一个 DigitalOcean 帐户,并正在尝试设置我的网站。但是,每当我输入我网站的 IP 地址时,我都会得到这个页面:


欢迎使用 nginx!

如果您看到此页面,则 nginx Web 服务器已成功安装并正在运行。需要进一步配置。

有关在线文档和支持,请参阅 nginx.org。 nginx.com 上提供商业支持。

感谢您使用 nginx。


我已经搜索了答案,但没有找到任何适合我的东西。我在 14.04 上运行 Ubuntu LEMP,并使用一键安装。我打算将我的页面/文件放入我已声明为根目录的“usr/share/nginx/html”文件夹中。

这是“etc/nginx/available-sites/default.conf”文件,希望能容纳这个:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost unaviamedia.ca;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    .........

}

但是,当我通过 IP 访问我的网站时,我仍然只能看到 Nginx 欢迎页面,这很烦人。如何显示主页?


编辑:更新代码以匹配我最近的尝试。另外,对于那些想知道的人,我已经重新启动了几次nginx。


如果我需要添加任何其他内容,请告诉我。谢谢!

【问题讨论】:

  • 不好意思问一下,你重载nginx了吗?
  • @Pixou,查看已编辑的问题(但是是的,我已经重新启动了 nginx - 假设这就是您的意思)。
  • ipv6only=on,那么这是否发生在 ipv4 和 ipv6 上?启用调试以记录错误,日志文件说明文件的来源?

标签: ubuntu nginx digital-ocean


【解决方案1】:

简化

创建一个“Hello world”index.html 并将其复制到项目的根目录*。

分而治之

我对你的建议是将你的 nginx.conf 剥离成一个非常简单的形式,如下所示。

server {
  listen 80 default;
  server_name yourdomainname.com;
  root /home/your_app_name/public;

  try_files $uri/index.html $uri ;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

组织

*我建议您不要将 index.html 放在 nginx 目录中。使用特定于您的项目的东西作为您的根目录,例如上面的示例。将您的 Hello World 索引页放在那里。

重启

现在重新加载 NGINX 并查看它是否正在加载您的简单“Hello World”index.html。如果是这样,开始增加复杂性,一次一个组件。

文件权限

基于 unix 的操作系统的第一大问题是文件权限。查看您的 NGINX 错误日志以查看您是否被文件和目录上的用户/组块ping通,这一点很重要。如果 NGINX 没有读取 index.html 的权限,游戏结束。


Digital Ocean 称他们的工具为“一键式安装”,这是一种误导。我有几个 DO VPS 设置,所以我知道他们的安装绝不是完整的安装,正如你所期望的那样。回到一次安装一个组件并确认每个组件都正常工作是最好的方法。

【讨论】:

  • 哦,我不是楼主的问题。
  • @Valerie 谢谢。事实证明,问题在于 DNS 传播时间比平时长。但是,我确实遵循了您的建议,以修复发生的其他几个错误。我想我也可能会听从你关于一键安装的建议。我安装了 LEMP,然后不得不安装 phpMyAdmin,并被它的简单程度震惊了。我认为这将是我从现在开始的默认操作。再次感谢!
  • 我很高兴它有帮助。祝你好运!
【解决方案2】:

只需将 https:// 与您的 IP 地址一起添加,而不是仅输入您的 IP 地址。 例如:https://198.168.5.158 这对我有用。

【讨论】:

    猜你喜欢
    • 2019-11-13
    • 2019-12-09
    • 2020-06-28
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多