User Tools

Site Tools


Wordpress on nginx

Install packages

apt install nginx php-fpm php7.0-mysql

Config file example:

upstream php {
    server unix:/var/run/php/php7.0-fpm.sock;
server {
	listen 80 ;
	listen [::]:80 ;
	return 301 https://$host$request_uri;
server {
	# SSL configuration
	listen 443 ssl ;
	listen [::]:443 ssl ;
	ssl                     on;
	ssl_protocols           TLSv1 TLSv1.1 TLSv1.2;
	ssl_session_cache       shared:SSL:10m;
	ssl_session_timeout     10m;
	ssl_prefer_server_ciphers on;
	ssl_certificate /etc/nginx/ssl/;
	ssl_certificate_key /etc/nginx/ssl/;
	# Note: You should disable gzip for SSL traffic.
	# See:
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See:
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	# include snippets/snakeoil.conf;
	root /var/www/example_site;
	# Add index.php to the list if you are using PHP
	index index.php;
	location = /favicon.ico {
                log_not_found off;
                access_log off;
	location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
	location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
                # test if this line below works like stuff ("RewriteRule . /index.php [L]") in .htaccess file for wordpress, used in apache server
                #try_files $uri $uri/ /index.php;
	location ~ \.php$ {
	       #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	       include fastcgi.conf;
	       fastcgi_intercept_errors on;
	       fastcgi_pass php;
	       fastcgi_buffers 16 16k;
	       fastcgi_buffer_size 32k;
	location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
	       expires max;
	       log_not_found off;

Tested on

  • Debian 9

See also


wiki/wordpress_nginx.txt · Last modified: 2022/08/16 12:28 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki