Why my nginx config for hiding jsp extension doesn't work properly? - nginx

I configure my Nginx web server with follow setting, It hides .jsp extension but doesn't appear my page.
location ~ \.(jsp)$ {
proxy_pass http://192.168.2.225:9595;
if ($request_filename ~* ^(.*).jsp$)
{
rewrite ^/(.*).jsp$ /$1 redirect;
break;
}
}

location ~ \.jsp {
return 403;
}
That will make *.jsp inaccessible. If you want them accessible but only via internal rewrites, then change the 'return 403;' to 'internal;'.

Related

How can I make a nginx.conf file to return different web pages for different subdomains?

I want to make my nginx to show a web page for this subdomain: abc.xyz.com and a different web page for this subdomain: abcd.xyz.com. How can I make that?
I tried to change the location block but it didn't work. Please help me.
You should list both domains in server_name directive:
server {
server_name abcd.xyz.com abc.xyz.com;
location /page {
}
location /anothe_page {
}
}
Or create two different servers as follow:
server {
server_name abc.xyz.com;
location /page {
}
}
server {
server_name abcd.xyz.com;
location /anothe_page {
}
}

Nginx - deploying static page

I have a web application deployed on an nginx with the server name example.com under the path var/www/app.
I added another directory, var/www/demo and it only contains a static .html page; is it possible to have it like example.com/demo?
I have already created a file in /etc/nginx/sites-enabled with the following content:
server {
location /demo {
root /var/www;
}
}
But it is not working, can someone help?
Read http://nginx.org/en/docs/http/ngx_http_core_module.html#root
server {
root /var/www/;
location /app {
index index.html;
}
location /demo {
index index.html;
}
}
Folder structure is
/var/www/app/
--- /var/www/app/index.html
/var/www/demo/
--- /var/www/demo/index.html
$# curl localhost/demo/
<html>
it works
</html>

Nginx set root to subfolder

With Nginx, i need the download folder to become the home page of my website, while still allowing the terms.html page to appear at the root. The download folder displays the list of files with the fancyindex and fancyindex_header directives.
I did this: root /var/www/html/download; but I no longer have access to pages outside the download folder like terms.html
does nginx allow this configuration? here is the structure of my directories:
www/
/download/ # fancyindex on + home page
/account/
/index.php
/login.php
/signup.php
/css/
/js/
robots.txt
terms.html
If your directory structure follows your URI structure, you should probably set the root to /var/www/html at the server level and use /var/www/html/download for one location only.
For example:
server {
...
root /var/www/html;
location / {
root /var/www/html/download;
fancyindex on;
}
location /account/ {
... # PHP stuff
}
location /css/ { }
location /js/ { }
location = /robots.txt { }
location = /terms.html { }
The last four blocks can be empty, as they inherit the value of root from the surrounding block. See this document for details.

Redirect search page to search result page using nginx

I want to redirect my page from
https://www.example.com/search?q=testtest or
https://www.example.com/search/?q=testtest
To
https://www.example.com/search-results/?q=testtest
So I have added below the code in nginx. But redirect not working.
location = /search {
if ($args ~ "q=([^/]*)/?$"){
rewrite ^/search-results/$ /?q=%1 redirect;
}
}

nginx not rewriting url for opencart

I have an opencart setup and I'm trying to get nginx to rewrite a url, yet I must be doing something wrong, as nothing I try will work. Here is what I have now that is not working. Just want to remove the index.php?route=common/home from the URL
server {
...
location /index.php?route=common/home {
rewrite http://www.site.com/ permanent;
}
}
How about this
server {
rewrite ^/index.php?route=common/home$ / permanent;
}

Resources