Category: wordpress

nginx configuration for wordpress in the subdirectory

I run my wordpress application on a local server, I write my content in this sandboxed server and then convert my website into html files and server it from s3 bucket as a static site. I helps me keep my server costs low and also keeps my website secure from unwanted attacks. I have multiple sites hosted within single nginx server and they are hosted a subdirectories. The below configuration helps me achieve that

server {
	listen 80 default_server;
	listen [::]:80 default_server;

	root /var/www/;
	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 / {
		try_files $uri $uri/ /index.php?$args;
	}

	location ~ \.php$ {
		include fastcgi_params;
		fastcgi_intercept_errors on;
		fastcgi_pass unix:/run/php/php-fpm.sock;
		fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
	}

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

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

	location ~ \.php$ {
			fastcgi_split_path_info ^(/muthu)(/.*)$;
	}

}

My website folder is present in the /var/www/ directory

Correct file permissions for wordpress

To keep your wordpress application secure, it’s root folder should be owned by www-data user. www-data is the user that web servers like Apache and Nginx on Ubuntu use by default for their normal operation. The web server process can access any file that www-data can access. It has no other importance.

If your wordpress folder is owned by root or any other user other than www-data, there is a change that you may not be able to install plugins, add themes or even upload files to your website from the dashboard. To fix the permissions you must execute the below mentioned commands in your shell.

sudo chown www-data:www-data  -R /var/www/wordpress_directory

Also fix the directory and file permissions using the below command

find . -type d -exec chmod 755 {} \; # directory permissions rwxr-xr-x
find . -type f -exec chmod 644 {} \; # file permissions rw-r--r--