I have installed a nginx server configuration on my localhost. It's a multi store PrestaShop 1.6.1.4. You can see the nginx configuration right here:
server {
listen 80;
listen [::]:80;
root /var/www/html/devsite;
index index.php index.html index.htm;
server_name .devsite.com;
location / {
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
try_files $uri $uri/ /index.php?$args;
}
# AlphaImageLoader for IE and fancybox
rewrite ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 last;
# Web service API
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
# Installation sandbox
rewrite ^(/install(?:-dev)?/sandbox)/(.*) /$1/test.php last;
#Change this block to your admin folder
location /admin {
if (!-e $request_filename) {
rewrite ^/.*$ /admin/index.php last;
}
}
# Source code directories
location ~ ^/(app|bin|cache|classes|config|controllers|docs|localization|override|src|tests|tools|translations|travis-scripts|vendor|var)/ {
deny all;
}
# Prevent exposing other sensitive files
location ~ \.(yml|log|tpl|twig|sass)$ {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I have arrived to the conclusion it's some sort of missing configuration with the Nginx Wildcard configuration, but I might be wrong, I'll quickly explain what I can see:
The page loads fine, admin works fine but there's a template that doesn't load the respective JS which enables the customer product selection process.
I have checked the inspector network debugger and I can see the file being loaded in the production environment correctly whereas it doesn't load as in the localhost environment...
Thanks for the help.
Things you may check, that have worked for me, at least once in the past:
Check the permissions in the local environment, i.e. use
namei -nom path/to/jsfile
to check that the path to the resource is accessible and ownership is appropriate (use chmod and chown to make appropriate alterations)
Check the permissions of the file itself (maybe an app or a process rewrites each time you run your service the js and file permissions are reset)
Check if you production instance is not really servicing the js file but has it cached from a previous state. Install maybe a clear cache button/add on or something that will allow you to deactivate cache. Some browsers have this feature.
Depending on your dev environment (is it Django is it something else?) it can be the case that servicing static files in the dev and in the prod environments might differ by design.
Check if the code you have in the dev and in the prod environments are really the same!
Stop the prod environment (if this won't interrupt any real service and won't bother your clients) and restart it. Do you experience the same issue?
Check again if both prod and dev look at the same nginx config file. Restart nginx and reload config
Try removing from dev nginx config the complex regex statements and check if js file can be serviced
Check locations of dev and prod static files and verify that they are proper in your config
As soon as I remember something additional I will post it here. Good luck!
I have a site using some old link pngs, like :
<img src="http://j.cd.top/uploads/jvyue/news/2020/04/10/15864804147273771862.png" style="height:211px; width:330px">
and the png is not present, so I tried to rewrite it to a local server by setting Nginx:
location ~ .*\.(gif|jpg|jpeg|png)$ {
try_files $uri #apache; }
location #apache{
rewrite ^http://j.cd.top/uploads/(.*)$ http://127.0.0.1:8222/$1 permanent;
}
http://127.0.0.1:8222 is local server that server images, but this settings not works, is something wrong?
http://j.cd.top/uploads is not the current website, it is a legacy link.
I also tried proxy pass :
location ~* \.(gif|jpg|jpeg|png)$ {
proxy_pass http://127.0.0.1:8222;
}
Scheme and hostname are not included in the $uri variable which is tested by rewrite directive, try this one:
rewrite ^/uploads/(.*)$ http://127.0.0.1:8222/$1 permanent;
Guys I am so bad at this nginx rewrite rules. Sad thing is that nginx is sooooo lightening fast that I cannot also quit using it.
Please help me.
I have installed SEO urls on the forum.
But i am unable to control the php files and the SEO urls both together.
If i open the SEO urls then php parser stops working and i can download the php source files instead.
/forum/compare-cameras-support-f1/
BUT if i open php URLs in format below they work fine.
/forum/viewforum.php?f=1
I have spent hours trying to make both work but have just given up.
location ^~ /forum/ {
# forum will run separate
# rewrite rules for forum
rewrite ^/(.*)-f([0-9]*)/(.*)-t([0-9]*)-s([0-9]*).html /forum/viewtopic.php?f=$2&t=$4&start=$5&$query_string break;
rewrite ^/(.*)-f([0-9]*)/(.*)-t([0-9]*).html /forum/viewtopic.php?f=$2&t=$4&$query_string break;
rewrite ^/(.*)-f([0-9]*)/index-s([0-9]*).html /forum/viewforum.php?f=$2&start=$3&$query_string break;
rewrite ^/(.*)-f([0-9]*)/ /forum/viewforum.php?f=$2&$query_string break;
rewrite ^/(.*)-f([0-9]*) /forum/viewforum.php?f=$2&$query_string break;
# app rewrite rules for the INSTALLATION
#try_files $uri $uri/ /forum/install/app.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
Please help
I have a website that has laravel setup to run under http://www.example.com/lara/
So, most Laravel pages have URLs of type http://www.example.com/lara/page/23 OR http://www.example.com/lara/category/23 etc.
Nginx is the underlying server and it has the following configuration to handle these requests:
location /lara/ {
try_files $uri $uri/ /lara/index.php?$query_string;
}
Everything works ok.
Now, I need to setup a special page with the URL http://www.example.com/mystuff/ which actually is handled by
http://www.example.com/lara/category/29
To get this working I added the following rewrite right below location /lara/, that is:
rewrite ^/mystuff/(.*)$ /lara/category/29/$1 last;
Unfortunately, I get a page not found error. Any insights?
Further investigation & research:
1)
location /mystuff/ {
return 301 /lara/index.php/category/29;
}
worked although that's not (browser address bar changes to) what I actually want.
2) Looks like Laravel is not seeing the updated REQUEST_URI.
Try this
server {
...
rewrite ^/lara/(.*)\..*$ $1/mystuff last;
return 403;
...
}
I've installed nginx, FastCGI and PHP on my server. WordPress 3.0 installed after a bit of a monster battle, but it's installed and working well.
However, when I change the permalink settings to anything other than default, I get 404 errors on every post, article and page.
I understand that this is something to do with nginx not supporting .htaccess and WordPress getting confused with where to go when a page is requsted.
I've tried a few rewrites in the nginx conf files and even the nginx compatibility plugin; neither have worked. With one rewrite I managed to stop the 404 errors, but instead of WordPress finding the post I was after I merely got my PHP confirmation page. Bah.
Forums are littered with people with similar issues. Does anyone have a solution?
On your location / block,
add this and remove any non-specific rewrite rules:
try_files $uri $uri/ /index.php;
If wordpress is on another directory besides the root, instead of having
if (!-e $request_filename) {
rewrite ^/wordpress/(.+)$ /wordpress/index.php?q=$1 last;
}
You can have:
location /wordpress {
try_files $uri $uri/ /wordpress/index.php?$args;
}
This page has exactly the same concept. I should have read and tried it first: nginx rewrite rule under a subdirectory
After much pain:
# if filename doesn't exist, take the request and pass to wordpress as a paramater
if (!-e $request_filename) {
rewrite ^/wordpress/(.+)$ /wordpress/index.php?q=$1 last;
}
If the requested file does not exist, pass it to index.php. It's a bit slow and I think I might try and not use a query, but it does work... :)
Have you tried the nginx Compatibility plugin?
Plus ElasticDog seems to provide a fairly concise article on getting WP working with nginx - which includes getting pretty permalinks to work.
Here's another article that seems to deal specifically with nginx rewrite rules for WordPress.
This was how I solved my permalinks in my wordpress blogs in dreamhost.
Inside the folder /home/ftpusername/nginx/example.com/ (if you don't have it, create it)
created the file
nginx.conf with the following content
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
restarted the nginx
/etc/init.d/nginx reload
Some notes:
ftpusername and example.com MUST be changed according to your system.
That was it!
Good luck for u all.
this does not work if you are using location other than / like:
~ .php$, what i meant to say that pretty link will work but your graphics will be all over the place. so what you need is exactly stated below.
http://www.pearlin.info
location ~ \.php$
{
try_files $uri $uri/ /index.php?$uri&$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?url=$1 break;
}
I did the following..
in the folder
/home/userrunningnginx/nginx/domain.com
I have:
default.conf (file)
include /home/neukbaarofnietps/nginx/neukbaarofniet.com/drop;
drop (file)
# Rather than just denying .ht* in the config, why not deny
# access to all .invisible files
location ~ /\. { deny all; access_log off; log_not_found off; }
nginx.conf (file)
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
WORDPRESS-NGINX.CONF (file)
#######################
# WP Super Cache
# if the requested file exists, return it immediately
if (-f $request_filename) {
break;
}
set $supercache_file '';
set $supercache_uri $request_uri;
if ($request_method = POST) {
set $supercache_uri '';
}
# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}
if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}
# if we haven't bypassed the cache, specify our supercache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host$1/index.html;
}
# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}
# all other requests go to Wordpress
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
Adding this block to your nginx.conf should solve the issue:
if (!-e $request_filename) {
rewrite ^/wordpress_dir/(.+)$ /wordpress_dir/index.php?q=$1 last;
}
Hope this helps.
Good luck.