Currently, I'm getting an error that the laravel image intervention package always return 404 error every time I try to access an image via URL manipulation.
My images are stored in 'storage/app/images' folder
My nginx config:
server {
listen 80;
server_name ######;
rewrite ^(.*) http://#####$1 permanent;
}server {
listen 80;
# access_log off;
access_log /home/#####/logs/access.log;
# error_log off;
error_log /home/#####/logs/error.log;
root /home/######/public_html/dtu-feedback-api/public;
index index.php index.html index.htm;
server_name ######;
# Custom configuration
include /home/######/public_html/dtu-feedback-api/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 32k;
fastcgi_buffers 8 16k;
fastcgi_busy_buffers_size 32k;
fastcgi_temp_file_write_size 32k;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\. {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|ttf|woff)$ {
gzip_static off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
location ~* \.(txt|js|css)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
}
And here is the log:
*1 open() "/home/#####/public_html/dtu-feedback-api/public/imagecache/medium/placeholder1.png" failed (2: No such file or directory)
Look like it tried to find the images in the imagecache path instead of the storage path.
So could you please help me with this error, thank you.
I found the solution, after I remove the
location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|ttf|woff)$ {
gzip_static off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
Then the image link starts working
Related
I am trying to setup nginx cache for Laravel application in order to cache Glide generated urls.
My host config template is as follows:
fastcgi_cache_path /tmp/nginx/cache levels=1:2 keys_zone=BACKEND:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
listen 443 ssl http2;
server_name ${URL};
root /var/www/backend/public;
index index.php;
ssl_certificate ${SSL_CERTIFICATE};
ssl_certificate_key ${SSL_CERTIFICATE_KEY};
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /favicon.ico { access_log off; log_not_found off; }
location /robots.txt { access_log off; log_not_found off; }
location ~ \.php$ {
fastcgi_pass ${CONTAINER}:9000;
try_files $fastcgi_script_name =404;
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 600;
fastcgi_cache BACKEND;
fastcgi_cache_valid 200 1m;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_cache_use_stale error updating timeout invalid_header http_500;
fastcgi_cache_lock on;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
error_page 404 /index.php;
#Cache everything by default
set $no_cache 0;
#Don't cache POST requests
if ($request_method = POST)
{
set $no_cache 1;
}
}
The cache seems to be working but the problem is that every glide generated image returns with status of 404, even though images are displayed and rendered correctly.
What could be causing such behaviour?
When I install it on the server - it doesn't work, i got blank screen with background and this.app is undefined error in console on server/nova/login page.
nginx config:
server {
listen 80;
listen [::]:80;
server_name wtw.test.loc;
root /home/test/sites/wtw/www/public;
access_log /home/test/sites/wtw/logs/access.log combined;
error_log /home/test/sites/wtw/logs/error.log warn;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ /\.(?!well-known).* {
deny all;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-wtw.test.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
I am setting up new laravel project with nginx server configuration ,in sites-available and sites-enabled files i have setup the laravel project details and i added host name in etc/hosts location also,when i hit url(http://hrmcc.test/) in browser i am facing file not found message in browser body,can you please help me to fix this issue
error in log
2022/08/17 13:24:34 [error] 4801#4801: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: hrmcc.test, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "hrmcc.test"
sites-available && sites-enabled
server {
listen 80;
server_name hrmcc.test;
root /home/deploy/hrm_v3.2/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/hrmc-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
}
Try to use the default Laravel NGINX configuration.
server {
listen 80;
listen [::]:80;
server_name example.com;
root /home/deploy/hrm_v3.2/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
This should work. Make sure that your php-fpm socket exists on the location in your configuration.
Also make sure to test your configuration by running nginx -t.
On my site conf I have:
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(ttf|ttc|otf|eot|woff|font.css|css|ico|js|gif|jpe?g|png|less|txt)$ {
etag on;
access_log off;
log_not_found off;
expires 180d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
add_header 'Access-Control-Allow-Origin' "*";
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_read_timeout 5m;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_max_temp_file_size 0;
proxy_set_header X-Forwarded-Proto $scheme;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
But then I try to access http://my-site-url/images/profiles/uid-of-my-image.jpg It's not being redirecting to php, where I have a script that generates this image.
Try adding a root directive specifying where the static files live along with try_files $uri $uri/ /index.php?$args; in your second location block that you've provided. Below is a sample config:
...
location ~* \.(ttf|ttc|otf|eot|woff|font.css|css|ico|js|gif|jpe?g|png|less|txt)$ {
root /absolute/path/to/static/files;
try_files $uri $uri/ /index.php?$args;
etag on;
access_log off;
log_not_found off;
expires 180d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
add_header 'Access-Control-Allow-Origin' "*";
}
...
Nginx version: nginx/1.10.0 (Ubuntu 16.04)
This is my blog conf:
server {
listen 80;
server_name blog.khophi.co;
root /var/www/html/blog;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location ~ /\.ht {
deny all;
}
}
As per steps here and here and here
I am able to visit the site homepage, but the article pages, like myblog.example.com/this-is-my-article doesn't work.
This might help,
just review every single line and remove which that you think you don't need,
its the config I always used for every wordpress setup
server {
listen 80;
server_name www.xxxxyour-domainxxxxx.com xxxxyour-domainxxxxx.com;
return 301 https://xxxxyour-domainxxxxx.com$request_uri;
}
server {
#listen 80;
listen 443 default_server ssl spdy;
server_name xxxxyour-domainxxxxx.com;
ssl on;
ssl_certificate /var/www/xxxxyour-domainxxxxx.com/noyoucant/xxxxyour-domainxxxxx.crt;
ssl_certificate_key /var/www/xxxxyour-domainxxxxx.com/noyoucant/xxxxyour-domainxxxxx.key;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 10s;
client_max_body_size 64m;
client_body_timeout 60;
#access_log /var/www/xxxxyour-domainxxxxx.com/xxxxyour-domainxxxxx.com.log;
error_log /var/www/xxxxyour-domainxxxxx.com/xxxxyour-domainxxxxx.com-error error;
root /var/www/xxxxyour-domainxxxxx.com;
index index.html index.php;
location / {
gzip_static on;
error_page 418 = #cachemiss;
if ($request_method = POST) { return 418; }
if ($query_string != "") { return 418; }
if ($http_cookie ~* "wordpress_logged_in_") { return 418; }
if ($http_cookie ~* "comment_author_") { return 418; }
if ($http_cookie ~* "wp_postpass_") { return 418; }
try_files "/wp-content/cache/all${uri}index.html" =418;
add_header "X-WPFC-Cache" "HIT";
# choose or modify any of the following cache-control headers
expires 30m;
# add_header "Cache-Control" "max-age=10, must-revalidate";
# add_header "Vary" "Cookie";
}
location #cachemiss {
try_files $uri $uri/ /index.php$is_args$args;
}
### SECURITY ###
error_page 403 =404;
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }
location ~* wp-admin/includes { deny all; }
location ~* wp-includes/theme-compat/ { deny all; }
location ~* wp-includes/js/tinymce/langs/.*\.php { deny all; }
location /wp-includes/ { internal; }
#location ~* wp-config.php { deny all; }
location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php)$ {
types { }
default_type text/plain;
}
### DISABLE LOGGING ###
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
### CACHES ###
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; }
location ~* \.(woff|svg)$ { access_log off; log_not_found off; expires 30d; }
location ~* \.(js)$ { access_log off; log_not_found off; expires 7d; }
### php block ###
location ~ \.php?$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_hide_header X-Powered-By;
#fastcgi_pass 127.0.0.1:9001;
fastcgi_pass unix:/xxxx/dir/php-fpm/php-fpm.sock;
#fastcgi_pass fpm;
add_header "X-WPFC-Cache" "MISS";
}
}