5

I have a laravel app on production (using Laravel Forge and a Digital Ocean droplet).

I'm able to access the app via www.domain.com, but if I try with the server's IP I get a 404 (nginx).

How can I manage to access the app with the IP address?

Thanks a lot for your help

EDIT:

Here is my Nginx config on Laravel Forge:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name domain.com;
    root /home/forge/domain.com/public;
    ...
}
chartalex
  • 51
  • 4

2 Answers2

7

This occurs because nginx searches for a configuration block containing default_server when no matching domain can be found. You can remove the default_server tag for the default(/etc/nginx/enabled-sites/default) and move it the config for the site you want to display by default:

server {
    listen      80 default_server;
    server_name example.net www.example.net;
    ...
}

your server block with updated default_server:

server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2;
    server_name domain.com;
    root /home/forge/domain.com/public;
    ...
}

Be sure to edit the default config to remove the default_server tag before restarting nginx, it is not allowed to have two config blocks with default_server. The config can be verified using nginx -t

more information can be found at the nginx documentation

MaartenDev
  • 5,631
  • 5
  • 21
  • 33
0

Why would you want to access your server from the naked ip?

Nginx returns a 404 since it cant find the requested domain on your server.

If you look at your folder structure your project folder corresponds to your site domain. It redirects you towards the right folder based on your domain name.

You could make a default project to show you something like phpinfo() when request trough the ip

Jasper Helmich
  • 668
  • 4
  • 21