Running Nginx and Drupal - nginx

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.

Related

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.

Correct regex expression for the location block inorder to capture CSS and JS when the request URL changes

I have developed nginx config file order to cater some custom error pages. I have created two location blocks to capture the main index.html file and other location to capture the css/js and the images. I have created the cs and the js files seperately and called into the main index file due to the ease of use. But this work only for the following types of url
https://example.com
https://example.com/abcd/
But if the url cahnges to
https://exmaple.com/abcd/efgd/ or more the css and js won't be in the response.
The css/js and images are in a directory named techops-page-resources. So after checking bit on the issue I found that on the first two url it'll get https://exmaple.com/resources as expected when the given domain is not available. But on the other occasions it'll transformed into https://example.com/abcd/resources/ and this uri doesn't exist. So I've tried different regex patterns and none of them seem to work. The following are the location blocks that I have implemented to set the error pages up.
error_page 503 /pages/maintenance.html;
error_page 502 /pages/50x.html;
error_page 404 /pages/40x.html;
location /pages/ {
root /var/www/html/ErrorPages/;
}
location /techops-page-resources {
alias /var/www/html/ErrorPages/pages/techops-page-resources/;
}
}
What I expecting is whenever the 404 error returns I want the main index file to call the techops-page-resources and include them in the the final customized 404 error page as expected. But currently what I only receive is the basic index.html file which is in the pages directory. Is there a correct regex pattern to match only the techops-page-resource as a postfix match as follows
location **some_regex_pattern**/techops-page-resources {
alias /var/www/html/ErrorPages/pages/techops-page-resources/;
}
I would love to do this in this same architecture without using inline css or js

Nginx rewrite '*/filename/playlist.m3u8' to '*/filename.mp4/index.m3u8' as redirect

I'm trying to migrate over from Wowza and set-up VOD on Nginx on Debian through the help of Kaltura's nginx-vod-module, everything is working fine, apart from the existing VOD archive still req. to be accessible through the old URLs... so a rewrite rule is in order, but since it's a bad practice to do this, it should be a nginx redirect 'return 301 '.
The previously used Wowza URL format for files in the VOD archive was:
http://<server-address>:<rtmp-port>/vod/<file-name>/playlist.m3u8
The new URL format has to be:
http://<server-address>/vod/<file-name><file-extension>/index.m3u8
While I don't know much about rewrite rules, for now I've managed to put together a temp solution:
location ~ playlist.m3u8$ {
rewrite ^(.*)/playlist.m3u8$ $1.mp4/index.m3u8;
}
But I don't know how would that translate into a working Redirect rule ('Return 301 ') or if it's possible to have one that would work universally without specifying each and every filename in the VOD folder.
While I'm at it, it kinda would be nice to have a simpler/shorter URL to access the newly added files.
http://<server-address>/vod/<file-name>.m3u8
The rewrite rule that should do that I think would be a combination of two rewrite rules, something like:
location ~ playlist.m3u8$ {
rewrite ^(.*)/playlist.m3u8$ $1.mp4/index.m3u8;
}
location ~ index.m3u8$ {
rewrite ^(.*).m3u8$ $1.mp4/index.m3u8;
}
But I'm worried it would target the URLs that have been rewritten and result in a HTTP error 404... suggestions to avoid that?
Try this:
rewrite ^http://(.*?):\d+/vod/(.*?)/.*?\.(.*)$ http://$1/vod/$2.mp4/index.$3
Regex101

NGINX rewrite issue

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

run cgi script using nginx

I am trying to execute cgi script on Nginx. In nginx.conf file, I added a location directive such as below:
location /cgi-bin{
root cgi-bin;
index index.cgi;
}
When I try to connect to http://example.com/cgi-bin/index.cgi, it says file not found. In error.log, I see the request as "http://example.com/html/cgi-bin/index.cgi.
cgi-bin is not in html folder. The correct path is "http://example.com/cgi-bin/index.cgi
I tried many possibilities for location directive. Either it looks in html/cgi-bin or it does /cgi-bin/cgi-bin/index.cgi. I am not sure why it uses 'cgi-bin' twice
Any suggestions.. I have been trying for hours now!!!

Resources