Nginx에서 WordPress를 사용하고 있지만 정적 파일의 캐싱을 활성화하려고 할 때마다 404가 발견되지 않습니다.Nginx 캐싱 404
이 내 /etc/nginx/conf.d/default.conf
파일입니다
server {
listen 80;
server_name _;
# SSL configuration
listen 443 ssl default_server;
ssl_certificate /etc/letsencrypt/live/shivampaw.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/shivampaw.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_session_timeout 30m;
ssl_session_cache shared:SSL:10m;
ssl_buffer_size 8k;
add_header Strict-Transport-Security max-age=31536000;
location/{
root /home/shivam/sites/shivampaw.com;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /home/shivam/sites/shivampaw.com;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 9;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json applicationx-javascript text/xml application/xml application/xml+rss text/javascript;
include wordpress/wordpress.conf;
그리고 이것은 WordPress.conf 파일입니다 : 그와
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
deny all;
}
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
, 그것을 잘 작동합니다. 내가 wordpress.conf의 목적을 위해
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
를 추가하고 nginx를 다시 시작하고 캐싱을 주석 모든 정적 파일이 404
생각해 내 사이트를 그래서 한 다시로드하지만 그것을 잘 작동합니다 .
아이디어가 있으십니까?
이 뜻은 WP-I를 rocket.conf (I 그것을 사용) 또한 제공 포함하면 404 WP-rocket.conf 그것을 캐싱 물건을 가지고 있기 때문이다.
기본적으로 정적 파일을 캐시 할 수없는 이유는 무엇입니까?
루트 위치 블록에 루트를 정의했기 때문입니다. 그래서 다른 위치 블록은 그것에 대해 알지 못합니다. 이것은 나쁜 습관입니다 ([here] (https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/) 참조). 이러한 위치 블록은 파일을 찾을 위치를 알 수 없습니다. 'location/{'블록 위에'root /home/shivam/sites/shivampaw.com; '을 가지고 있어야하고'try_files $ uri $ uri /index.php? $ args'를 각각의 정적 파일에 추가해야합니다 블록. 또 다른 방법은 설정을 유지하면서 각 블록에'alias/path/to/static/files /; '를 추가하는 것입니다. –
감사합니다 @KeenanLawrence - 답장으로 게시 해 주시기 바랍니다 :) – Shiv
제발 @shiv입니다. 답변을 수락하십시오 :) –