Simpel dan langsung, ini adalah catetan saya untuk konfigurasi virtual host nginx dan php-fpm di CentOS 6 untuk simukti.net yang menggunakan zend framework 2.
server {
listen 80;
server_name simukti.net;
rewrite ^(.*) https://www.simukti.net$1 permanent;
access_log off;
error_log off;
server_tokens off;
}
server {
listen 80;
server_name www.simukti.net;
rewrite ^(.*) https://$server_name$1 permanent;
access_log off;
error_log off;
server_tokens off;
}
server {
listen 443;
server_name www.simukti.net;
ssl on;
ssl_certificate /etc/ssl/certs/ca-bundle.crt;
ssl_certificate_key /home/simukti/certificates/simukti.net.decrypt.key;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RC4-SHA:AES256-GCM-SHA384:AES256-SHA256:CAMELLIA256-SHA:ECDHE-RSA-AES128-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:CAMELLIA128-SHA;
set $fpm_hostport 127.0.0.1:9000;
set $app_path /home/simukti/WebApplications/$host/public;
set $index_file index.php;
error_log /var/log/nginx/www.error.log;
access_log off;
server_tokens off;
include /etc/nginx/mime.types;
root $app_path;
index $index_file;
sendfile on;
keepalive_timeout 20;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_types text/plain text/css application/x-javascript text/xml
application/xml application/xml+rss text/javascript application/json;
location / {
root $app_path;
index $index_file;
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.*)$ /$index_file?$args last;
}
location ~ \.php$ {
include fastcgi_params;
root $app_path;
fastcgi_pass $fpm_hostport;
fastcgi_index $index_file;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
location ~* ^.+.(txt|png|gif|jpg|jpeg|css|js|swf|ico|md|bmp|pdf|doc|docx|ppt|pptx|zip) {
access_log off;
expires 360d;
}
location ~ /\.ht {
deny all;
}
if (!-e $request_filename) {
rewrite ^.*$ /$index_file last;
}
}
Saya menggunakan variabel untuk php-fpm host port, application path, dan pusat input request (index file)
set $fpm_hostport 127.0.0.1:9000;
set $app_path /home/simukti/WebApplications/$host/public;
set $index_file index.php;
Dan juga untuk baris terbawah saya tambahkan aturan, jika tidak ada file yang dituju, arahkan ke index.php. Itu karena pada request tertentu, artikel yang mestinya ada menjadi Not-Found (404) jika tidak ditambahkan aturan tersebut.
if (!-e $request_filename) {
rewrite ^.*$ /$index_file last;
}
Semoga bermanfaat.