This problem occurs when Openresty accesses the first page of the root directory as a Web server:
Configuration of Nginx side:
1Worker_processes 2;2Error_log Logs/error.log;3 4 Events {5Worker_connections 1024;6 }7 8 http {9 server {TenListen 8080; One server_name localhost; A -Location/ { - index index index.html index.htm; theRoot/usr/local/openresty/nginx/work; - - } -Location/dir { +Default_type "Text/plain"; -content_by_lua_file/usr/local/openresty/nginx/work/resources/lua/Index.lua; + } A at } -}
Only in the Nginx configuration, there is no problem, but the actual use of the error occurred, the page rendering also appeared a problem, just the text output, the rest of the response.
Multi-query verification, so far, the problem of the solution is to add Content-type configuration in the response header of the server, there are two solutions, one is the Openresty more_set_headers module method, the other is the use of Nginx method add_ The header command adds Content-type content to response, which solves that approach.
MIME type
MIME is a specification that guarantees non-ASCII file propagation on the Internet. Originally used for messaging systems except that ASCII is the content of plain text files, it can be used in other formats such as images. Later, browsers also support this specification, so in addition to text formats such as HTML, there can be many other formats.
When the browser receives the response file of the server, it enters the plug-in system through the content of the response header Content-type to find out which plug-in can recognize the received file. If the plugin is missing, you will be prompted to download the plugin, so content-type content determines whether you can render the content you want to render correctly.
Common MIME Types
Hypertext Markup Language text. HTML HTML text/html
Plain text. txt Text/plain
RTF text. rtf Application/rtf
GIF graphics. gif image/gif
JPEG graphics. ipeg jpg image/jpeg
Au sound file. Au audio/basic
MIDI Music file Mid midi Audio/midi,audio/x-midi
RealAudio music files. RA Ram Audio/x-pn-realaudio
MPEG files. MPG MPEG Video/mpeg
AVI file. avi Video/x-msvideo
gzip file. GZ application/x-gzip
Tar file. Tar Application/x-tar
See more here.
The Internet has a special organization IANA to confirm the standard MIME type, but the internet is growing too fast, and many applications can't wait for the IANA to confirm that they use the MIME type as the standard type. So they use a method that begins with X in the category to identify that the category has not yet become a standard, such as X-gzip,x-tar. In fact, these types are widely used and have become the standard of fact. As long as both the client and the server recognize this MIME type, even if it is not a standard type, the client program can handle the data according to the MIME type using specific processing methods. Both the standard and common MIME types are set by default in Web servers and browsers (including operating systems), and only for uncommon MIME types, you need to set up both the server and the client browser for identification purposes.
Because the MIME type is related to the suffix of the document, the server uses the document's suffix to differentiate between MIME types for different files, and the server must define the correspondence between the document suffix and the MIME type. When the client receives data from the server, it simply accepts the data stream from the server and does not know the name of the document, so the server must use additional information to tell the client the MIME type of the data. Before sending real data, the server sends the MIME-type information of the flag data, which is defined using the Content-type keyword, for example, in an HTML document, the server will first send the following two lines of MIME identity information, which is not part of a real data file.
Content-type:text/html
Note that the second behavior is a blank line, which is required, and the purpose of using this empty line is to separate the MIME information from the true data content.
After using the add_header instruction, the response content-type contents of the index.html inline. js file and the. css file are changed correctly, and the problem at the beginning of this article is no longer present. However, Chrome still only shows the text, the various JS and CSS effects are not triggered, the problem is not resolved ....
Finally, the unconscious use of other browsers, including IE and other browsers to access the file, the results rendered content is correct. Try Chrome again, there's still a problem ... Do you need to consider browser compatibility? Or the other? First here to write down the problem, to solve the problem to be filled!
"Essay" MIME type