Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Nginx allows very flexible request routing. I will show you a way to set up</p> <ul> <li>a default route passed to a <a href="http://nodejs.org/">node.js</a> backend</li> <li>another route passed to a <a href="http://php-fpm.org/">php-fpm</a> backend</li> <li>alternative route passed to a typical apache + mod_php backend</li> <li>got js, images, css and other files on the nginx machine? serve them the fastest way directly from nginx</li> </ul> <p>I like, and I think that's the default setup layout for most distros, to have <code>conf.d</code> and <code>vhosts.d</code> directories with <code>active</code> and <code>available</code> folders. So I can easily disable a vhost or configuration file by simply deleting the symlink.</p> <pre><code>/etc nginx.conf vhosts.d/ active available conf.d/ active available </code></pre> <p><strong>/etc/nginx.conf</strong></p> <pre><code># should be 1 per CPU core worker_processes 2; error_log /var/log/nginx/error.log; # I have this off because in our case traffic is not monitored with nginx and I don't want disks to be flooded with google bot requests :) access_log off; pid /var/run/nginx.pid; events { # max clients = worker_processes * worker_connections worker_connections 1024; # depends on your architecture, see http://wiki.nginx.org/EventsModule#use use epoll; } http { client_max_body_size 15m; include mime.types; default_type text/html; sendfile on; keepalive_timeout 15; # enable gzip compression gzip on; gzip_comp_level 6; gzip_types text/plain text/css text/xml application/x-javascript application/atom+xml application/rss+xml application/json; gzip_http_version 1.0; # Include conf.d files include conf.d/active/*.conf; # include vhost.d files include vhosts.d/active/*.conf; } </code></pre> <p><strong>/etc/nginx/vhosts.d/available/default.conf</strong></p> <p>Say our document root for static files is <code>/srv/www/vhosts/static/htdocs</code></p> <pre><code>server { server_name _; listen 80; root /srv/www/vhosts/static/htdocs; # if a file does not exist in the specified root and nothing else is definded, we want to serve the request via node.js try_files $uri @nodejs; # may want to specify some additional configuration for static files location ~ \.(js|css|png|gif|jpg) { expires 30d; } location @nodejs { # say node.js is listening on port 1234, same host proxy_pass 127.0.0.1:1234; break; } # just for fun or because this is another application, we serve a subdirectory via apache on another server, also on the other server it's not /phpmyadmin but /tools/phpMyAdmin location /phpmyadmin { rewrite /phpmyadmin(.*)$ /tools/phpMyAdmin$1; proxy_pass 10.0.1.21:80; break; } # files with .php extension should be passed to the php-fpm backend, socket connection because it's on the same and we can save up the whole tcp overhead location ~\.php$ { fastcgi_pass unix:/var/run/php-fpm.sock; include /etc/nginx/fastcgi_params; break; } } </code></pre> <p>create a symlink to make the default vhost active</p> <pre><code>ln -s /etc/nginx/vhosts.d/available/default.conf /etc/nginx/vhosts.d/active/. /etc/init.d/nginx restart </code></pre> <p>See how simple and intuitive the nginx configuration language is? I just HAVE to love it :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload