Question

Change default web root for nginx on one-click install lemp 14.04

https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04

All of these steps were taken, no effect at all.

accessing the droplet via http all it does is show the default web page “ssh to configure your lemp installation”

Even when accessing via putty it says “default web root is” /var/www/html even after all the changes.

I’m just trying to deploy my Laravel app to the vps and the setting up part is taking longer than the coding itself.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

@Vanker

The way the repository packages are setup, files in:

/etc/nginx/sites-available

are symlinked to:

/etc/nginx/sites-enabled

i.e

/etc/nginx/sites-available/default => /etc/nginx/sites-enabled/default

The NGINX configuration file located at /etc/nginx/nginx.conf then loads the files from:

/etc/nginx/sites-enabled

You can confirm this by looking at the bottom of the http block for a line that shows:

include /etc/nginx/sites-enabled/*

It may also look like:

include sites-enabled/*

Changes should reflect regardless of whether you modify the link or the actual file.

Changes to the web root that NGINX uses are reflected by modifying root in the server block. If it’s current using /var/www/html, i.e.

root /var/www/html;

You’d simply change that line and reload/restart NGINX.

That being said, you may find it more beneficial to clean up the server block and remove the clutter so that you’re not sifting through commented lines that have no bearing on your configuration.

The server block you posted would look like the following, once cleaned up:

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

    server_name domain.com www.domain.com;

    root /var/www/html;

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

I removed try_files $uri /index.php =404; from the location ~ \.php$ block as it really shouldn’t be needed.

I also changed $query_string to $args as it’s more commonly used.

That said, you may need the index line if it’s not defined in nginx.conf, so we can add that back line so:

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

    server_name domain.com www.domain.com;

    root /var/www/html;

    index index.php index.html;

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

That being said, the one-click images are meant to be a starting point. You still need to know how to manage a server, setup the server, etc. Server/System administration, much like coding, isn’t a one-time deal that requires no further setup, configuration, or tweaking/tuning – it’s on-going.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This comment has been deleted

@Vanker

Please post the contents of /etc/nginx/nginx.conf and also, check the directory to make sure that the file containing your server block data actually exists at the location you are using.

So if nginx.conf is set to:

include /etc/nginx/sites-available/*;

Then your server blocks need to be in /etc/nginx/sites-available, i.e.

/etc/nginx/sites-available/default
/etc/nginx/sites-available/site01
/etc/nginx/sites-available/site02
/etc/nginx/sites-available/site03

etc.

@Vanker

If you only use one site, then just edit whatever file is located in /etc/nginx/sites-enabled

If you want to run multiple sites on the one-click installation, then I would recommend that you remove all files in /etc/nginx/sites-enabled/* and /etc/nginx/sites-available/*, and then create a new configurations by following the tutorial.

In the tutorial, everything with the color red are something you should modify.