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.

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.

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Featured on Community

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more