ubuntu - 显示 Nginx 页面而不是主页(Digital Ocean - LEMP)

标签 ubuntu nginx digital-ocean

我最近购买了 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 好几次。

<小时/>

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

最佳答案

简化

创建一个“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 错误日志以查看文件和目录上的用户/组 block 是否对您执行 ping 操作非常重要。如果NGINX没有读取index.html的权限,游戏就结束了。

<小时/>

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

关于ubuntu - 显示 Nginx 页面而不是主页(Digital Ocean - LEMP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30485369/

相关文章:

docker - Ubuntu中DigitlOcean Droplet上的BigBlueButton

ubuntu - 在 Ubuntu 20.04 上安装 Redhawk 尝试启动 OmniOrb 服务但失败并出现以下错误 :

ubuntu - 使用 LDAP 配置测试链接不起作用

apache-flex - Nginx 上的安全沙箱违规

nginx - 现有 Nginx 重写规则的表单 url

digital-ocean - 在DCOS中安装Flink出错

docker - 如何在 Digital Ocean 液滴上运行 docker 镜像?

python - mySQL 加载数据 - 第 1 行不包含所有列的数据

shell脚本获取eth0的网关地址

javascript - 在 Node js 中将静态文件保留在内存中是否明智?