我希望有人访问http://abhinav.epaper.lc/media时,他应该从/home/ankurgupta/websites/lc/uploads/abhinav.epaper.lc /
获取内容但是http://abhinav.epaper.lc/media/a.jpg总是返回404错误。 但是/home/ankurgupta/websites/lc/uploads/abhinav.epaper.lc/a.jpg中存在a.jpg
这是配置:
server {
listen 80;
listen [::]:80;
server_name abhinav.epaper.lc;
root /home/ankurgupta/websites/lc;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /media {
alias /home/ankurgupta/websites/lc/uploads/abhinav.epaper.lc;
}
location ~ \.php$ {
try_files $uri =404;
include nginxconfig.io/php_fastcgi.conf;
}
include nginxconfig.io/general.conf;
}
nginxconfig.io/general.conf;
# security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
. files
location ~ /\. {
deny all;
}
# assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
access_log off;
}
# svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
access_log off;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
nginxconfig.io/php_fastcgi.conf;
# default fastcgi_params
include fastcgi_params;
# fastcgi settings
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$base/:/usr/lib/php/:/tmp/";
fastcgi_intercept_errors off;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
答案 0 :(得分:0)
删除以下几行可解决问题
位置〜*。(?: css(.map)?| js(.map)?| jpe?g | png | gif | ico | cur | heic | webp | tiff?| mp3 | m4a | aac | ogg | midi?| wav | mp4 | mov | webm | mpe?g | avi | ogv | flv | wmv)$ { 到期7天; access_log关闭; }