Nginx page displaying instead of home page (Digital Ocean - LEMP)
Asked Answered
M

3

7

I recently bought a DigitalOcean account, and am attempting to set up my web site. However, whenever I enter the IP address of my site, I get this page:


Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com.

Thank you for using nginx.


I have searched for answers, but have not found anything that works for me. I am running Ubuntu LEMP on 14.04, and used the one-click installation. I am planning to put my pages/files into the "usr/share/nginx/html" folder, which I have declared as the root.

Here is the "etc/nginx/available-sites/default.conf" file to hopefully accomodate this:

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;
    }

    .........

}

However, I am still only getting the Nginx welcome page when I access my site by IP, and it is getting annoying. How can I show the home page?


Edit: Updated code to match my latest attempt. Also, for those who are wondering, I have restarted nginx several times.


Let me know if I need to add anything else. Thanks!

Miner answered 27/5, 2015 at 14:24 Comment(3)
sorry to ask, but did you reload nginx ?Animator
@Pixou, see edited question (but yes, I have restarted nginx - assuming that is what you meant).Miner
ipv6only=on, so is this happening on ipv4 and ipv6? enable debug for error logging, what does the logfile say where files are served from?Beetle
K
8

Simplify

Create a "Hello world" index.html and copy it into your project's root directory*.

Divide and conquer

My suggestion to you is to strip your nginx.conf down to a very simple form, like the one below.

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;
}

Organization

*I would recommend you not have your index.html in an nginx directory. Use as your root directory something that is specific to your project, like in the example above. Place your Hello World index page there.

Restart

Now reload NGINX and see if it is loading your simple "Hello World" index.html. If so, start to add complexity, one component at a time.

File permissions

The #1 gotcha on unix based OS is the file permissions. It's important to look at your NGINX error logs to see if you're getting pinged by user/group blocks on files and dirs. If NGINX does not have permission to read index.html, game over.


Digital Ocean calls their tools "one-click installs" and this is misleading. I have several DO VPSs setup, so I know that their installs are not by any means complete installs, as you'd expect. Going back to installing components one at a time and confirming each is working is the best method.

Kielce answered 28/5, 2015 at 16:36 Comment(3)
Oh, I'm not the owner question.Merylmes
@Valerie Thanks for this. It turns out that the problem was a long-than-usual DNS propagation time. However, I did follow your suggestion in order to fix several other errors that occurred. And I think I may also follow your suggestion about the one-click installs. I installed LEMP, and then had to install phpMyAdmin, and was shocked by how easy it was. I think that will be my default action from now on. Thanks again!Miner
I'm glad it helped. Good luck with it!Kielce
F
1

If you come across this issue, try this:

Remove the default site if it exists:

sudo rm /etc/nginx/sites-enabled/default

Test your Nginx configuration:

sudo nginx -t

If the test passes, reload Nginx:

sudo systemctl reload nginx

Then retry opening your domain for about 10 mins.

Fike answered 17/8 at 17:25 Comment(1)
Removing that default site worked for meRichel
P
0

Just add https:// along with your IP address instead of just entering your IP address. Eg: https://198.168.5.158 This worked for me.

Peba answered 22/2, 2022 at 6:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.