NGINX alias with HHVM - nginx

I'm trying to reroute one of my web directories to another project directory in the home folder. But when I try and access the page, I get served a blank file
I believe the fault in on the try_files $uri $uri/ /rtstaging/index.php?$query_string; line. But I'm new to using nginx, so any help would be much appreciated
server {
listen 80;
listen [::]:80;
root /home/default/public;
index index.php index.html index.htm;
server_name nu-voo.co.uk www.nu-voo.co.uk;
include hhvm.conf;
location /rtstaging/ {
alias /home/rtsearch/public/;
try_files $uri $uri/ /rtstaging/index.php?$query_string;
include hhvm.conf;
}
}

Related

Nginx always responding with default index.html

I am so new for deploying things.I am just trying to deploy 2 different websites with nginx. I checked a few documents and videos but my second website which knowinapp is not working as well. Whenever I am checking the website it is showing default index.html or the other my website's index.html I don't know what I am missing.
default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
knowinapp.conf file
server {
listen 80;
listen [::]:80;
server_name knowinapp.com www.knowinapp.com;
root /var/www/knowinapp.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
The problem was about browser cache things. So, I was checked on different browser and saw the website works well... Or you can delete the cookie and site data.

Reverse proxy nginx to itself

I am currently hosting a single-page react app that is hosted in the URL root like so:
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
try_files $uri /index.html;
}
}
I need to put the site behind an AWS elastic load balancer and at the same time change the path so everything is within a /support directory e.g. http://example.com/index.html -> http://example.com/support/index.html.
AWS ALBs do not support URL rewriting so I have to do this within the nginx config on the server. First of all I tried changing the config to:
server {
listen 80;
server_name localhost;
location /support {
alias /var/www/html;
try_files $uri /index.html;
}
}
This sort-of works but the URLs within the javascript content don't contain the /support path (e.g. they contain http://example.com/script.js instead of http://example.com/support/script.js).
I then tried creating a reverse-proxy config to proxy /support to /, which sadly put nginx in an infinite loop until it ran out of worker threads:
server {
listen 80;
server_name localhost;
location /support {
proxy_pass http://localhost:80;
}
location / {
root /var/www/html;
try_files $uri /index.html;
}
}
I'm confused why requests are going into a reverse-proxy loop? Shouldn't proxy_pass remove the /support prefix before proxying the request, and therefore it shouldn't be "caught" again by the /support location?
Just a guess.
Do you want to serve something on /?
If not - it is easy:
server
{
listen 80;
server_name localhost;
location /support/
{
alias /var/www/html/;
try_files $uri $uri/ /index.html;
}
location /
{
return 303 http://localhost/support$request_uri;
}
}
Fiddle around with the ending slashes if it does not work (using them - or not - makes often a difference).
Use alias instead of root so that /support is not added to the /var/www/html folder.
Everything gets redirected to /support.
If you want to serve something on / which is different from /support:
Use sub_filter or subs_filter in /support to rewrite your source code links on-the-fly so that they will never use /.
If you have redirects inside your source code (or proxy_pass backend) - you need proxy_redirect and/or Lua to catch and change them on-the-fly.

nginx to always serve the root index.html in every path

I have currently the code below. I am wondering if it's possible to still service this root even though I go to other pages like http://localhost/dog. The problem with my command below is it will return 404
server {
listen 80;
server_name localhost;
location / {
root /usr/src/app/angularjs/dist;
}
}
It is possible. Add the try_files directive to your location block, this will tell nginx to load all requests that cannot be matched to a filesystem path with your index.html:
try_files $uri /index.html;

Serving static content with nginx alias, what is the difference between /dir and /dir/?

I'm setting up an nginx server to serve an index.html page that I have stored in /data/www/test/.
Here is my config file (/etc/nginx/sites-enabled/default):
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location /test/ {
alias /data/www/test/;
index index.html;
}
}
I can curl 0:80 and see the contents of /usr/share/nginx/html/index.html.
I can curl 0:80/test/ and see the contents of /data/www/test/index.html.
But when I curl 0:80/test I get a 404.
I want to be able to see that html whether I type /test or /test/.
Can someone please explain what is happening here?
Thanks!
Just like the format, request for /test return test file, the config will match location / and find test file in root path. you can try doing touch /usr/share/nginx/html/test and access /test again
Request for /test/ will match location /test/, at the content phase, it look the index file in the root/alias specified location.

Nginx Redirects Subfolders

I have on my server installation of WordPress in public directory:
var/www/example/ - main installation of WordPress
In that directory I have also subdirectory WORDPRESS which has many subfolders like
var/www/example/WORDPRESS/1
var/www/example/WORDPRESS/2
etc.
Every this subfolders 1,2 have installed WordPress Blog. Everythings works ok when I use standard permalinks for wordpress for example:
http://www.example.net/WORDPRESS/1/?p=1
But when I try to change it to somethink like:
http://www.example.net/WORDPRESS/2015/09/27/title-of-post
Nginx redirect to:
http://www.example.net/2015/09/27/title-of-post/
My nginx configuration:
server {
listen 80;
server_name example.net *.example.net;
rewrite ^/(.*)$ http://www.example.net/$1 permanent;
}
server {
listen 80;
server_name www.example.net;
root /var/www/example/;
index index.php index.html index.htm;
client_max_body_size 128M;
location / {
root /var/www/example/;
index index.php index.html index.htm;
try_files $uri $uri/ /index
}
How can I make subfolders work? Nginx just skips WORDPRESS subdirectory in link.
I think you can try with:
location /WORDPRESS/ {
root /var/www/example/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}

Resources