Here is a short yet more than enough guide for the most to tweak Nginx PHP5-FPM WordPress setup running on Ubuntu 14.04 on Rackspace Cloud Server. The same settings might not work if you are not using at least a 2 GB PVHVM Instance. It is a potentially bad habit to use an underpowered server with swap memory on cloud setup.
Nginx PHP5-FPM WordPress : Understand The Infrastructure Before Major Tweaks
If suddenly the visitor increase over week, your server will crash like a hell making SSH impossible. Most importantly, if this bad habit of using underpowered server combined with too much caching is continued, on dedicated server or bare metal it can catch fire. There are two commands to test – top
(Q to exit) and uptime
. Without second user, for Nginx, there will be two users – root and www-data. Load average is expressed in this way – 0.05, 0.07, 0.05
. This are fully and kernel related. If the traffic analogy goes to 1.00, it means it is exactly at capacity and should probably either double the RAM or add more nodes. There are parameters like multicore versus multiprocessor to consider. For this reason, high end website should use the full managed service of Rackspace. Infrastructure Level Support will kill huge time just to optimize.
We are assuming that the reader is following our method – WordPress Nginx php5 fpm Installation on Rackspace Cloud followed by Optimizing Nginx and better to Setup Separate Database Server. Two server is minimum configuration separating application server and general purpose web server.
---
There is no meaning if you are using a 512 MB server to save money on Rackspace for production website. There are different qualities of web masters and websites. Nginx needs lesser RAM never means you’ll not use a powerful web server. Apache2 is too heavy plus with load condition of Apache2 usually goes more bad.
Nginx PHP5-FPM WordPress : Major Tweaks
This is a generalized guide assuming a 2 GB instance. You must test load and page loading time to get the best result. We are mentioning the files and name of the string indicates “need some tweak”. Always perform config test with nginx -t
on production server before reloading.
/etc/nginx/nginx.conf :
We have discussed before, if something is remains :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | # middle of the file http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay off; keepalive_timeout 15; keepalive_requests 2000; types_hash_max_size 2048; server_tokens off; server_name_in_redirect off; open_file_cache max=1000 inactive=300s; open_file_cache_valid 360s; open_file_cache_min_uses 2; open_file_cache_errors off; server_names_hash_bucket_size 64; # server_name_in_redirect off; client_body_buffer_size 128K; client_header_buffer_size 1k; client_max_body_size 2m; large_client_header_buffers 4 8k; client_body_timeout 10m; client_header_timeout 10m; send_timeout 10m; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## error_log /var/log/nginx/error.log; access_log off; # Gzip Settings ## gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 9; gzip_min_length 1000; gzip_proxied expired no-cache no-store private auth; gzip_buffers 32 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## skipped stuffs include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; # end of the file } |
Run nginx-t
and then its OK, do service nginx reload
.
/etc/nginx/fastcgi_params :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param HTTPS $https; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 256 4k; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; |
/etc/php5/fpm/php-fpm.conf :
1 2 3 4 5 6 7 8 9 10 11 12 13 | open_basedir ="/var/www/" ; commented out three lines ; debug the next ; disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstarus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,dl,system,shell_exec,fsockopen,parse_ini_file,passthru,popen,proc_open,proc_close,shell_exec,show_source,symlink,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec ,highlight_file,escapeshellcmd,define_syslog_variables,posix_uname,posix_getpwuid,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,escapeshellarg,posix_uname,ftp_exec,ftp_connect,ftp_login,ftp_get,ftp_put,ftp_nb_fput,ftp_raw,ftp_rawlist,ini_alter,ini_restore,inject_code,syslog,openlog,define_syslog_variables,apache_setenv,mysql_pconnect,eval,phpAds_XmlRpc,phpA ds_remoteInfo,phpAds_xmlrpcEncode,phpAds_xmlrpcDecode,xmlrpc_entity_decode,fp,fput,virtual,show_source,pclose,readfile,wget expose_php = off max_execution_time = 30 max_input_time = 60 memory_limit = 128M display_errors = Off post_max_size = 2M allow_url_fopen = off default_socket_timeout = 60 |
/etc/php5/fpm/pool.d/www.conf :
1 2 3 4 5 6 7 8 9 10 | user = www-data group = www-data listen = /var/run/php5-fpm.sock listen.owner = www-data listen.group = www-data listen.mode = 0666 pm = ondemand pm.max_children = 5 pm.process_idle_timeout = 3s; pm.max_requests = 50 |
We talked about Nginx default config file a lot, this is the best practice in excerpt for using W3 Total Cache.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | server { # many things # set cache = request set $cache_uri $request_uri; # we are serving php files with a query string live if ($request_method = POST) { set $cache_uri 'null cache'; } # conditional nullifying if ($query_string != "") { set $cache_uri 'null cache'; } # if has post cache then serve from there else get from WordPress # kinda logic, "do not waste our visitors time" location / { try_files /wp-content/cache/page_enhanced/${host}${cache_uri}_index.html $uri $uri/ /index.php?$args ; } } |
Others are written here for W3 Total Cache with SSL. With this setup and a bit minifying, using Cloud files, you’ll get around 93/100 score with A A A A [variable] [variable] [variable] score on Webpage test.
Tagged With AMAY , digital innovation