NGINX rewrite issue - nginx

I have NGINX + PHP5-fpm and slim for routing, my website wont work with out this rewrite : try_files $uri /index.php; , now everything is fine and all site is ok except some API, for example http://example.com/webservice/android.php/get_video_info
It doesn't work and say it :No input file specified.
Why ? i should mention that http://example.com/webservice/android.php is exist on server but "http://example.com/webservice/android.php/get_video_info" is not exist and its just a post action on this android.php
PS : if you need more information i will provide for you

It was about my app.config, after I checked the NGINX log i found that the issue it's make path duplicated like /var/www//var/www/ after i change my config and remove second one, issue is solved

Related

React app - Blank page for all pages with a dynamic URL, on nginx server

Locally, the app works correctly.
When deploying it on a ubuntu server, there is a problem with this route:
<Route path="/combination/:some_id" exact component={SomePage} />
I'm using a BrowserRouter.
When clicking on a link, the url in the address bar is updated to the correct one, but I'm not redirected to the page.
When trying to access a page (i.e http://my_ip/combination/hjg234jg2323jh4g) all I can see is a blank (white) page.
I think the problem is with nginx configuration, because locally it works. and other routers work (/contact-us)
My /etc/nginx/sites-available/default file contains:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri /index.html;
}
You need to add only base href="/xyz" in your index.html file.
If you added basename in history, then base href should be equal to
basename or else put only / .
There is no problem in the configuration of the default file.
It's worked well for me.

Can't get nginx to match part of the path

I have nginx running as in a docker-compose setup and I want to achieve to following:
Every url that contains /something/ is passed to application 1
Every url that contains /something/alsothis/ is passed to application 2
My current config has:
location ~* ^/something/(?<path>.+) {
proxy_pass http://app1/$path;
}
location ~* ^/something/alsothis/(?<path>.+) {
proxy_pass http://app2/$path;
}
When I try https://www.example.com/something/rest_of_path it is working fine.
However when I try https://www.example.com/something/alsothis/rest_of_path I get an Unkown error in Postman (500 error is logged in nginx).
Also I double checked that app2 is working. When I change to the first location to app2, it also works fine.
Can't seem to figure out what is going wrong, all help is much appreciated.
Thanks in advance!
Richard was right, just had to change the order.

Rewrite URL /blog/content/images/**/* to /content/images/**/*

My front-end is hitting /blog/content/foo/bar.jpg when looking for static assets.How can I make NGINX redirect those requests to /content/foo/bar.jpg instead?
At first I tried this:
location ~ ^/blog/content/ {
root /var/www/ghost/content/;
}
Apparently it didn't work – (btw, I'm testing each change in the .conf file with a sudo nginx -s reload + F5 in the browser.. is there a better way to test/debug NGINX behavior (and actually understand what's going on instead of this "worked / didn't work" feedback I get with each F5?)
Then, I tried this one I found in a cheatsheet – at the server level:
rewrite ^/blog/content/(.*)$ /$1 last;
Again, without luck. What bothers me is that I can't even see what the line above is doing and why it isn't working.
Someone, please, get me out of this "google for a solution -> try something that looks promising --> hit F5 hoping it works (it doesn't) -> google for a solution" loop.
The solution I found was to rewrite with:
rewrite ^/blog/(.*)$ /$1 last;
But it isn't ideal. I'd prefer to rewrite only when the URI contains "/blog/content/"..

Expose files to public via rewrite

I'm using nginx docker engine for a symfony app, and I have some images under /var/www/html/project/ezplatform/files/(.*) that i need to expose them to the public.
I tried to add under my nginx configuration this rewrite config:
rewrite "^/var/www/html/project/ezplatform/files/(.*)" "/app.php" break;
rewrite "^/var/www/html/project/ezplatform/files/(.*)" "/var/www/html/project
/ezplatform/files/$1" break;
But still facing an exception 404 Not Found when I try to access to an available image.
Any idea would be appreciated.
Try adding a location block to your nginx conf, where you define a handle for the images directory, which nginx then uses to retrieve files from the full path. Like:
location /other_images/ {
alias /var/www/html/project/ezplatform/files/;
}
You can link to the images using your 'virtual' folder path:
other_images/example.gif
(So in HTML, <img src = "other_images/example.gif">, or use whatever the symfony syntax is for image links.)
Let me know if this solves the 404 Not Found problem.

Running Nginx and Drupal

I am new to Nginx but I managed to install Drupal on windows 8 machine. I just noticed that this URL(http://localhost:8080/drupal/) spits out error message 403 Forbidden. If I mutate that URL a bit by including the index(http://localhost:8080/drupal/index.php) file then it works as expected. My question is this:
How could I configure Nginx so that I wont get error message when I go to http://localhost:8080/drupal/?
Depending on your configuration, an index directive will encourage nginx to look for specific files when encountering a directory:
index index.php;
For a more specific rule, to single out that one path and map it to the controller, you could use an exact match location directive:
location = /drupal/ { rewrite ^ /drupal/index.php last; }
See this and this for more.

Resources