Configure Nginx for WordPress

Deploy config files

WordPress config file

$ sudo vi /etc/nginx/global/wordpress.conf
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;
}

location ~ \.php$ {
	#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	include fastcgi_params;
	fastcgi_intercept_errors on;
	fastcgi_pass php;
	#The following parameter can be also included in fastcgi_params file
	fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
	expires max;
	log_not_found off;
}

Site specific config file

$ sudo vi /etc/nginx/sites-available/www.lama-lab.mydns.jp.conf
# Redirect everything to the main site. We use a separate server statement and NOT an if statement - see http://wiki.nginx.org/IfIsEvil
 
server {
        server_name  _;
        return 302 $scheme://www.lama-lab.mydns.jp$request_uri;
}
 
server {
    server_name www.lama-lab.mydns.jp;
    root /misc/extHDD/www.lama-lab.mydns.jp;
 
    access_log /var/log/nginx/www.lama-lab.mydns.jp.access.log;
    error_log /var/log/nginx/www.lama-lab.mydns.jp.error.log;

    index index.php;
 
    include global/restrictions.conf;
 
    # Additional rules go here.
 
    # Only include one of the files below.
     include global/wordpress.conf;
#    include global/wordpress-ms-subdir.conf;
#    include global/wordpress-ms-subdomain.conf;

    listen 80;
    listen [::]:80;
}

Enable the Web site

$ sudo ln -s /etc/nginx/sites-available/www.lama-lab.mydns.jp.conf /etc/nginx/sites-enabled/www.lama-lab.mydns.jp.conf
$ sudo systemctl restart nginx
$ sudo systemctl restart php-fpm

Last Updated on June 5, 2024 by lama-admin


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *