Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shawnyv's avatar
Level 13

Help with nginx & serving internal app

Hi all,

I'm trying to get a laravel app set up for a client on their internal network (no access from outside world).

This is the first time I've had to do any server management stuff outside Forge, and it definitely paints a compelling picture why I never want to work without forge!

I've followed this tutorial to get my app set up on the new server, and it's worked beautifully, EXCEPT that I can't figure out how to actually get it to load in the browser (all my commands are working fine though).

https://medium.com/@grmcameron/deploying-your-laravel-web-app-1faaa66f3302

I'm sure there's something simple I'm missing between my sites-available files (and maybe the /etc/hosts ?), but I can't for the life of me figure it out, and all my googling to this point hasn't helped.

I'd like the site to load either with the server IP, OR with an alias that can be accessed by any connection that has permissions to see it (IE me when I'm VPN'd into the remote server).

EG: I'd love either http://123.45.67 or http://my_pretty_name.com to work (without having to link my_pretty_name.com, of course)

I've tried various combinations of server_names in the available-sites file(s) to no avail... EG:

''' listen 80 default_server; listen [::]:80 default_server;

    root /var/www/mySiteDir/public;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;

    #server_name _;
    server_name mySiteIp;

'''

Any help would be much appreciated

0 likes
7 replies
burlresearch's avatar

try a solitary server config like this:

server {
  listen 80 default_server;
  server_name my_pretty_name.com;
  root /var/www/mySiteDir/public;
  index index.php index.html;
  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }
}

and remove any server block from your /etc/nginx/nginx.conf file. This should do 2 things:

  1. set the default for any IP-only incoming requests
  2. match a specific request for your my_pretty_name.com domain

And, then even if you do have a entry in

/etc/hosts

123.45.67 my_pretty_name.com

It would still proxy the request.

shawnyv's avatar
Level 13

Thanks so much for your help @burlresearch!

I'm closer, but still missing something... The pretty address still isn't working, but when I go to the IP it's now downloading the artisan file.

Still showing nothing in the browser though.

Any additional help would be super appreciated!

burlresearch's avatar

If the PHP file is being downloaded, and not rendered, there is chance you are missing the PHP processor, like FPM, try:

$ sudo apt-get install php-fpm 

and you may still have some other dependencies to install if your LEMP server is still incomplete. Hopefully that will help you get on the right path.

If ther server_name still isn't resolving - are you sure you've edited the hosts file on your client machine?

keevitaja's avatar

this is what i use in my docker dev env

user user;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    client_max_body_size 200m;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /home/user/logs/nginx-access.log;
    error_log /home/user/logs/nginx-error.log;

    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

daemon off;
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name ~^(.*\.)?(?<domain>.+)\.localhost$;

    root /var/www/$domain/public;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/run/php/php7.3-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

and you probably want php packages from this repository

add-apt-repository -y ppa:ondrej/php
shawnyv's avatar
Level 13

Hi @burlresearch,

I've got the php7.2-fpm in place, but it doesn't seem to be doing anything right now. I've set the /etc/hosts on my client machine, but it's just downloading the artisan file as well. Same thing as when I hit the server IP.

@keevitaja - thanks for your answer - I don't have any fastcgi in my config, I"ll have to give that a shot.

Thanks to everybody for their help on this - server side stuff is definitely not my forte, and it's making me appreciate Forge so much more!

Shawn

shawnyv's avatar
Level 13

I realized I was wrong above - the file it's downloading is the index.php file from the public directory.

The server was created for me, and I was given non-root access (I've got to use sudo to do anything in it).

Could this whole thing be a permissions issue?

I've set the laravel application folder to 755.

This is my server conf file:

server {
    listen 80 default_server;
  listen [::]:80 default_server;

  server_name myprettyurl.com;
  root /var/www/mysite/public;
  index index.html index.htm index.php;

  location / {
        try_files $uri $uri/ /index.php?$query_string;
  }

    error_log  /var/log/nginx/default-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.{
        deny all;
    }
}

That's in my /etc/nginx/sites-enabled and /etc/nginx/sites-available directories

I've got php7.2-fpm installed, as well.

This is all so frustrating - it's getting to the index.php page, but just forcing download instead of rendering.

Thanks for any additional insight!

shawnyv's avatar
Level 13

Okay - looks like a lot of this was me being stupid.

I think I was forgetting to symlink the available-sites file correctly to enabled-sites, and didn't have the correct permissions in place.

Anyway - thanks so much for helping put me on the right path all!

Shawn

Please or to participate in this conversation.