I don't know why Drupal stopped generating thumbnails. So, I get error on files like this:
/sites/default/files/styles/choices/public/a1531172504.jpg?itok=Wn-VWDKd
Although the full image is found in:
/sites/default/files/a1531172504.jpg
I'm working on Nginx, Drupal 7
Last time I've answers question related to image derivatives I've got minuses so let be thorough here.
1.Drupal core will NOT create image derivative upon image upload - fact.
2.Thumbnail image (derivative from original image) is physically created upon HTTP request eg. if you visit the listing where image is used (when you visit the listing with thumbnail image the derivative is created on the fly via HTTP request)
3.To alter this behavior and to get a derivative image instantly upon image upload via CCK field you must use module Imageinfo Cache https://www.drupal.org/project/imageinfo_cache
With this info form above please recheck your site (go to listing where the thumbnail should appear and than check your thumbnail folder) If the image is still missing please provide more details like: Are you using CCK field or is it a custom field, are you creating derivative programmatically? Some code snippets are required here to solve you problem.
Also please check your .htaccess located in sites/default/files/.htaccess (not the general .htaccess)
and while you there check the permissions on files folder.
The solution for me was to add this lines to the nginx.conf files:
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
try_files $uri $uri/ #rewrite;
}
location #rewrite {
# not working with Drupal rewrite module: rewrite ^/?(.*?)/?$ /index.php?q=$1&$args;
rewrite ^/?(.*?)/?$ /index.php/$1&$args;
}
My environment is:
- docker-compose with nginx (nginx:1.17.4-alpine), drupal
(drupal:9.0.6-fpm-alpine) and mysql (mysql:8.0)
- drupal (9.0.6), nginx/1.17.4, PHP 7.4.10, MySql 8.0.21
The server responded with a 404 error because:
The image styles are generated when drupal receives a request.
Nginx receives a request for an image that is not in the filesystem; then returns a 404 instead redirect the request to drupal.
The rule I propose for the nginx.conf redirect the image request to drupal and solve the problem after restart the web server:
docker-compose restart webserver
My fix was to disable and re-enable the clean-url. .../admin/config/search/clean-urls".
Related
I explain you my situation,
I have a website that we'll called website-a.com that is link to my personal project.
On this project, every users can have a page, with the url my-project.com/[username]. So the urls will then be my-project.com/user1, my-project.com/user2, ...
For the context, I'm building it in Next JS, with the following code architecture :
--
pages
-- [username]
-- index.tsx
-- about.tsx
--
And I'm using Nginx with pm2 and a proxy pass that points to my http://localhost:3000
Now, I'd like to redirect a second domain name to a specific page of a user.
So I would like that when I go to user1.com, it displays my-project.com/user1 without modifying the url.
I pointed the DNS of user1.com to my server, I created a new host nginx and I made a proxy_pass to http://localhost:3000/user1. It's working, but I don't have the ressources css and js, because next is trying to load them from user1.com and they don't exists (user1.com/css/abc.css, ...).
I also tried to modify the build-manifest.json in the .next folder created after the build and it didn't work
So either I would like to find a way for Next JS to take the resources from my-project.com even if it is on user1.com (let it be an absolute path), or put a configuration with the nginx host but I don't don't know which one.
Thanks you for your help
Newby at Nginx on Ubuntu. Main site is a WordPress site "example.com". No issue with this site. However, I need (cause someone did things in IIS and we need to move it to Nginx) to have a another site at "example.com/testsite" (not Wordpress, just static HTML).
Since this "testsite" was originally in IIS, sloppy coding was done and things are a complete mess of upper and lowercase.
So, I added a location block to my /ect/nginx/sites-enabled/example.com.conf
location /testsite {
alias /home/myusername/public_html/testsite;
index index.html;
}
This works! However as soon as a try to make this location case insensitve, I get a 404.
location ~* /testsite {
alias /home/myusername/public_html/testsite;
index index.html;
}
Ideas? Also, this site has tons of links that users can click on that are a mixture of upper/lower/proper and in no relation to the actual files that are on the server. Is there a way to make anything under that location block case insensitive (aka IIS way of doing it).
Thanks everyone.
Here is what I need to do - I need my server to serve up two versions of a set of images. The first set of images are real PNG files that sit in a folder on my server, call it /realimages. The second set of images do not actually exist. When they are requested I want to take the requested image file name e.g.
https://example.com/nosuchimage/img1.png
generate the image via the index.php script sitting inside the /nosuchmage folder (or elsewhere if easier).
That script does the following
Picks up a related image from the /realimages folder
Uses PHP GD to generate a background
Superimposes the related image on the background
serves up the result
That script has been written and is fully functional. What I do not know is how to force all PNG image requests to the /nosuchimage folder to be redirected to that script with the original request passed as a script parameterr.
I know that doing this a relatively trivial configuration issue with NGINX which involves writing a rewrite rule. However, NGINX rewriting is still quite a black art to me. Hopefully, someone here will be able to tell me just what that rewrite rule should be.
To redirect all the images of a certain folder, just use the code below in your configuration file.
In my case I will use the default file.
/etc/nginx/sites-available/default
location ~ \/realimages/(.+\.png)$ {
return 302 $scheme://$server_name/nosuchimage/$1;
}
// Access: http://www.example.com/images/valdeirpsr.png (Exists & Redirect to /nosuchimage/valdeirpsr.png)
// Access: http://www.example.com/images/valdeirpsr2.png (Not Exists & Redirect to /nosuchimage/valdeirpsr2.png)
To redirect only the images not found in a particular folder, just use the code below in your configuration file.
location ~ \/realimages/(.+\.png)$ {
error_page 404 $scheme://$server_name/nosuchimage/$1;
}
// Access: http://www.example.com/images/valdeirpsr.png (Exists & Show Image)
// Access: http://www.example.com/images/valdeirpsr2.png (Not Exists & Redirect to /nosuchimage/valdeirpsr2.png)
i just moved my server from apache to nginx, and my main site from joomla to wordpress (now it is a lot faster, but it cost me two months of learning nginx, and testing new configs etc.). Only problem that left is with new links structure.
Can somebody help me to rewrite old links to the new one?
This is mine links structure:
OLD> http://www.example.com/this-is-just-some-text-1234.html
NEW > https://www.example.com/this-is-just-some-text-09878
Main text in most cases stays the same, but post-id number is changed, and there is no .html at the end. http > https redirects are in nginx config already.
This can't really be done with nginx alone -- how would nginx have any idea what was the old ID with Joomla, and the new one with WordPress? It sounds like your transition process wasn't done correctly.
However, if you do have a list of old and corresponding new URLs, you can use the the map directive within nginx to supply such list.
map $uri $new_uri {
/this-is-just-some-text-1234.html /this-is-just-some-text-09878;
}
if ($new_uri) {
return 301 $new_uri;
}
References:
http://nginx.org/r/map
http://nginx.org/r/if
I am caching my websites pages into a static flat file cache and am trying to use a try_files directive to load the file first from cache if it exists and then go to web application.
I'm basically trying to do something like this:
try_files $uri $uri/ /var/www/vhosts/example.com/httpdocs/staticfilecache/$uri/index.html
In this example if the user requested example.com/products/ it would try staticfilecache/products/index.html The problem I have is that $uri already contains a trailing slash. Trying to use this with $uriindex.html creates an error.
Is there any performant/easy way to always strip the / but not rewrite the address in the browser?
What you are trying to do has many problems on many levels.
"/var/www/vhosts/$uri" is invalid. Except if you have duplicated
your whole document root under the staticfilecache folder.
Nginx has it's own caching system and will check it first by itself
without any intervention from you as long as it has been setup.
Nginx will check for index files by itself as long as the index directive has been set.
Your code is actually attempting to check the staticcache last and
not first as you said you wanted.
There is no point in creating a static file cache on disk. Nginx can
just as well read the static files from their original locations.
In any case, Nginx will create the cache for items that need cache,
usually dynamic files, by itself. It is not a manual job.
Basically, it looks like you are a bit on the wrong track on some webserver fundamentals.
The answer(strictly) to your question is,
rewrite ^(.*)/$ $1 break;
But I would recommend you don't do this and go through #Dayo's answer.
For some interesting stuff for caching guidance, you can check this out.