I kept getting this error when I upload a photo to my site.
Unable to create directory wp-content/uploads/2016/06
The configures are like this . For /etc/nginx/conf.d/default.conf
server {
server_name vnfintech.com www.vnfintech.com;
root /usr/share/nginx/html;
index index.php;
access_log /var/log/nginx/vnfintech.com.access.log;
error_log /var/log/nginx/vnfintech.com.error.log debug;
client_max_body_size 20M;
set $cache_uri $request_uri;
# POST requests and URLs with a query string should always go to PHP
if ($request_method = POST) {
set $cache_uri 'null cache';
}
if ($query_string != "") {
set $cache_uri 'null cache';
}
# Don't cache URIs containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php |sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $cache_uri 'null cache';
}
# Don't use the cache for logged-in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+
|wp-postpass|wordpress_logged_in") {
set $cache_uri 'null cache';
}
# Use cached or actual file if it exists, otherwise pass request to WordPress
location / {
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html
$uri $uri/ /index.php;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}
location ~ .php$ {
try_files $uri /index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
#include fastcgi_params;
#fastcgi_pass 127.0.0.1:7777;
}
# Cache static files for as long as possible
location ~*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
expires max;
log_not_found off;
access_log off;
}
}
For /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
client_max_body_size 20M;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
}
php-fpm
process
ps aux | grep php-fpm
root 9616 0.0 0.0 283908 5828 ? Ss 03:40 0:00 php-fpm: master process (/etc/php-fpm.conf)
nginx 9646 1.3 0.1 349956 64200 ? S 03:40 0:10 php-fpm: pool www
nginx 9647 1.3 0.1 349956 64100 ? S 03:40 0:10 php-fpm: pool www
nginx 9656 1.0 0.1 348928 62884 ? S 03:40 0:08 php-fpm: pool www
The permission of wp-upload
is chmod -R
as 775, and chown -R
as nginx:nginx
ls -l /usr/share/nginx/html/wp-content/uploads/
total 60
drwxrwxr-x. 6 nginx nginx 4096 Jun 18 01:57 2015
drwxrwxr-x. 3 nginx nginx 4096 Jun 18 01:57 2016
What is wrong that I can't upload any photos to the server?
Best Answer
Your problem will likely be SELinux.
This is a non-standard place to put web related files (on CentOS), which would normally go in /var/www/html. As such the default policy will not allow httpd_t (nginx)to write to usr_t files and directories.
You can move your files into /var/www/html... and run restorecon or you can add a new regex to the SELinux database to set the file contexts for your root path