I have a simple static site generated with Jekyll that I'm using an Nginx server to host. The site is in two languages but that is currently only done with different versions of pages being at different URLs. It doesn't currently do anything with the accept-language header. I thought it would be nice to be able to at least set the 404 page based on language as it is only currently in English.
I'm not very familiar with Nginx configuration and my current configuration is very simple:
error_page 404 /404.html;
location ~* ^(.+)/$ {
try_files $uri /$1/index.html /$1.html =404;
}
The alternative language 404 page would just be another static file, e.g. /404-ca.html
Related
For some reason, a page is forwarding to an nginx-served 404 page. The site is working except for this one page. On my landing page, I have the following in the header:
<meta http-equiv="refresh" content="5;URL=/second">
Even hard coding http://mydomain.local/second serves up the same 404.
This is a Sinatra deployment.
get "/second" do
#title = "my Title"
erb :index
end
I am thinking maybe my locations directive in nginx.conf is a bit screwy:
location / {
autoindex off;
try_files $uri $uri/ $uri/$request =404;
index /;
}
Anybody have any insight why Sinatra wouldn't capture the route and just serve up the file? Cheers.
Lets break this down:
autoindex off;
You don't need to specify this, it's off by default.
try_files $uri $uri/ $uri/$request =404;
Try and match requests to files in this order, serve the first one which matches. If none match, return 404. Your request is http://mydomain.local/second, so you are telling Nginx to look for:
webroot/second
webroot/second/
webroot/second/GET /second HTTP/1.1
Return 404
The index directive tells Nginx how to handle requests ending with a slash, you would normally specify files likely to be index files within your project, eg index.php, index.html etc. You don't really use this and try_files together as they serve a similar purpose.
Also worth noting that Nginx adds a trailing slash to any request which doesn't have one and doesn't end with a file extension, so it may also be the case that get "/second" do needs to change to get "/second/" do, as I doubt Sinatra ever sees the request without the trailing slash appended
We are runnning a Wordpress web site on nginx + php-fpm7 on Ubuntu. We have problems with Unbounce plugin and their support cannot help. The plugin has a popup, which dynamically creates a page (.html) which loads inside the popup. Since this file physically doesn't exist the nginx returns a 404 (see screenshot). How can I configure the nginx to pass this request further to php-fpm?
This is my try_files directive in my nginx config:
location /
{
try_files $uri $uri/ /index.php?$args;
}
My full nginx configuration is here. Does anyone have an idea of how to achieve this?
I'm trying to use nginx error_page directive (link) to show error pages.
This is my code so far:
error_page 404 /site/404.html;
location /site/404.html {
try_files $uri =404;
break;
}
But what I really want is show this 404.html page only if the url is www.example.com/example. And not show this 404.html error page if the url is only www.example.com. Is it possible to achieve this behavior using error_page directive?
I have an s3 bucket that contains directories and html files. I'm using nginx in front of the bucket and have configured a proxy_pass to the bucket, which works fine. I want clean URLs without the html extension, and for these URLs to resolve properly. For example, instead of foo.com/bar/my-file-name.html, this must be accessible at foo.com/bar/my-file-name
The primary question here is how to prevent requiring the .html at the end of every URL. As in, I want nginx to handle routing each requests and try looking for a file with the .html extension, and then return it.
My problem is that I can't figure out how to force nginx to try_files like I would on a non-S3 site. When I do try and add any configuration of try_files, it breaks the site by returning HTTP 500 errors on all paths.
For comparison, here is the configuration that works great on a non-S3 backed site (with the files on the server itself):
location / {
try_files $uri $uri/ #htmlext;
}
location #htmlext {
rewrite ^(.*)$ $1.html last;
}
My goal is to replicate this behavior with a proxy_pass to an S3 bucket and force it to try filenames with an .html extension other than index.html, which works out of the box.
Here is my current configuration that works great, minus any html files other than index.html:
location / {
proxy_pass my-bucket.s3.blahblah/;
}
I've got a few questions about Nginx that I can't seem to find a clear answer on. I'm currently having with my WordPress Multisite—the images aren't showing up. A common problem, easily solved with some .htaccess file modifications. But this server uses Nginx, so I need to dig into nginx.conf. A few questions below:
Do I modify the sites-available/mysite file, or should I be using the html/nginx.conf for this type of thing?
Do I need to restart Nginx after modifying my conf files?
A few things to consider:
I'm using subdirectories in my WordPress multisite
The site is loading and functioning properly, the WordPress configuration—or rather, some of its required redirects—are the only thing that needs to be altered.
Thanks so much for any help.
Do I modify the sites-available/mysite file, or should I be using the html/nginx.conf for this type of thing?
Using custom configurations (sites-available/your-conf) is prefered when using nginx.
nginx can also be used as a load-balance system just by these configs.
Do I need to restart Nginx after modifying my conf files?
Yes you do.
Below is an sample configuration (which is already running with proper naming instead of wordpress.
Also, official documentation about Wordpress Mulltisite may give you an idea.
server {
listen 80;
root /var/www/wordpress;
index index.php index.html index.htm;
access_log /var/log/nginx/wordpress.access.log;
error_log /var/log/nginx/wordpress.error.log;
# Make site accessible from http://localhost/
# Add wordpress.local.com to your hosts.conf file if not an alive host
server_name wordpress.local.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
include fastcgi.conf;
}