F
F
for_stupid_answer2015-06-20 14:55:20
Nginx
for_stupid_answer, 2015-06-20 14:55:20

Serve files as html regardless of extension, nginx, how?

How to configure nginx to serve files without extension as html and not as plain text data?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2015-06-20
@sim3x

http {
    default_type    text/html;

nginx.org/en/docs/http/ngx_http_core_module.html#d...

X
xbox, 2015-06-25
@xbox

First, you describe the locations in the usual way, in which you specify how to handle different paths on the site.
After the usual locations at the very end, you make the following location:

location ~ /*\.(.*) {  			
     root "/var/www/path_to_site/";	
}

In the above example, the path after root needs to be corrected to your own.
With this configuration, regular locations will be checked first, and if none of them work, then a file with any extension will be given.
For example, you can first set locations for html pages, for php files, for jpg files, for various redirects depending on the address of the requested page, etc., and then for everything else (in this case, for any files) that did not fall under separate regulations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question