0
votes

I am an amateur with servers and I am setting up Nginx on my local ubuntu machine. I have multiple sites up and working locally as practice for transfer to a live server. I am unsure if this is the best setup for the sites in question. They are wordpress sites.

Each sites folder is in var/www

/var/www/site1
/var/www/site2

I sym linked the default file in /etc/nginx/sites-available/default to /etc/nginx/sites-enabled/default. Keeping it as is. Noting the listen parts especially;

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

Using this file as a basis, I did the same for both sites, creating separate file for each in sites available and sym linking them to sites-enabled. Here is site1s setup;

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

        root /var/www/site1;
        index index.php index.html index.htm;

        server_name local.site1.com; #for testing, edited in hosts

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

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

My question is simply; is this an efficient way of setting up the Nginx server? This thread lists my setup as an option, but nothing on its efficiency. I left default in sites-enabled as the 'default_server' with my actual sites simply listening to port 80; I'm not really clued up on ports..

I feel like asking about having a 'dedicated' database server (block) for each site at this point, but maybe that is an entirely different kettle of fish..

1
What sort of efficiency are you worried about?Brad
I've heard Nginx scales with response to demand (unlike Apache) but I don't know if there is any special configuration to enable this or if it just 'works' by defaultmyol
Neither Nginx nor Apache can automatically scale anything... for that you're usually talking about multiple servers and something else entirely. Nginx has a more efficient threading model than Apache, which is probably what you've heard about. And, since that has to do with how Nginx was designed and not configuration, it does just work.Brad

1 Answers

3
votes

You config is OK, just use includes, and you can change global parameters for all sites from 1 file.

site1s.conf:

server {
   root /var/www/site1;
   server_name local.site1.com; #for testing, edited in hosts

   include /etc/nginx/conf.d/global.cnf;
}

site2s.conf ... siteNs.conf cloned from site1s.conf (you change just 2 lines with hostsnames )

/etc/nginx/conf.d/global.cnf (or any name you like, but better not .conf extension for avoid auto-loading by nginx - i dont know all your configs):

listen 80;
listen [::]:80;

index index.php index.html index.htm;

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

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