<code>server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.auceo.cn;
root /data/www;
include /etc/nginx/default.d/*.conf;
location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$ {
root /data/www;
expires 7d;
}/<code>
問題 然後index.html能訪問,配置圖片不能訪問,找了半天錯誤,為啥不能訪問圖片,然後查到原來是用戶訪問權限問題,
<code>user nginx;/<code>
默認是上面的,所以不能訪問。然後改成
<code>user root root;/<code>
然後在訪問就可以展示圖片,沒有403問題了。
但是為了避免直接用Root 可以創建www用戶及用戶組
然後直接把/data目錄及子目錄改為www用戶
<code>[root@VM_58_190_centos www]# chown -R www:www /data
drwxr-xr-x 5 www www 4096 Jan 9 13:50 data/<code>
然後nginx-conf配置如下
<code>user www www;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.auceo.cn;
root /data/www;
include /etc/nginx/default.d/*.conf;
location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$ {
root /data/www;
expires 7d;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
————————————————
版權聲明:本文為CSDN博主「Au感」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/sinat_33716023/article/details/79017754/<code>
閱讀更多 達升笑聊IT 的文章