Skip to content
Ethan Gallant edited this page Oct 8, 2018 · 11 revisions

PHP is most efficient when used in Fast CGI Mode.

Install php5 process manager

#apt-get install php5-fpm

Next Steps:

  • create a CSR and either self-sign or get a legit ssl certificate
  • create a file in /etc/nginx/sites-available/[your servername]
  • create a symbolic link in /etc/nginx/sites/enabled
  • restart nginx

Note: This can work without SSL. Just change port 443 to port 80 and remove the SSL lines.

Create file [your servername]:

upstream php {
   server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
    server_name [your server name];
    return 301 https://$host$request_uri;
}

server { 
  listen 443;
  server_name [your server name];

  ssl on;
  ssl_certificate /etc/ssl/certs/[your server certificiate];
  ssl_certificate_key /etc/ssl/private/[your server key];
  ssl_prefer_server_ciphers on;
  keepalive_timeout 15;

  # Adjust to your installation location  
  root /usr/share/nginx/www/MPOS/public; 

  location = /favicon.ico {
    log_not_found off;
    access_log off;
  }

  location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
  }

  location ~ /\. {
    deny all;
  }

  location ~ /(templates|include)(/|$) {
    deny all;
  }

 # Directives to send expires headers and turn off 404 error logging.
  location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; 
       log_not_found off; 
       expires max;
  }

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

  location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;	
        fastcgi_pass php;
  }
}