Nginx is a popular web server that can be used to serve static HTML pages. This article will show you how to respond to all Nginx requests with a static HTML page. First, create a new file in your project’s root directory called nginx.conf. This file contains the configuration for Nginx. In this file, you will need to set up some basic settings for Nginx. In the nginx.conf file, you will need to set up the following: server_name www.example.com www2; listen 80; # Set this value to point to your web server’s port number (80 by default) proxy_pass http://www2; proxy_set_header X-Forwarded-For $proxy_add_xfer; proxy_set_header X-Forwarded-Proto http; # Set this value to point to your web server’s protocol (HTTP by default) proxy_setenv X-FORWARDED-PROTO “http” ; # Set this value so that Nginx can send requests through your web server’s firewall
So once we got into the HSTS preload list, nobody could to go http://feeds.howtogeek.com anymore, and Feedburner’s custom DNS option didn’t support HTTPS. So it was time to switch to our own thing.
The quick and easily solution was to serve up all requests to a static copy of our RSS feed that we had stored in the index.html file. To force nginx to serve that file whether somebody went to /howtogeek/ or /howtogeek/1 or even /howtogeek1 was as simple as using the try_files directive.
You’ll just want to edit your server or location block with try_files like this:
Replace the /index.html part with whatever your static HTML page is. Once you’re done you’ll have a block kinda like this, which will send every request to the file index.html which should be found in the root directory, in this case /data/webroots/feeds/.
Restart nginx with a
command, and you’re all set.