nginx中SSI问题的研究,nginxSSI问题研究
nginx中SSI问题的研究,nginxSSI问题研究
最近感觉挺爽的,这个项目团队没有一个专门做PHP的,我是第一个进来做PHP(当然还有前端)的,哈哈,我会设计修改出适合我们业务的PHP框架,哈哈,感觉会学到很多东西的样子,前几天在组内20几个前辈面前讲php框架,以及跟大牛们探讨适合我们的php框架,感觉表达能力太差了,知道的东西表达不清楚,还要我的导师去帮我表达,这里感谢下我的导师于洪磊(简称磊哥),磊哥简直就是我的偶像,我没见过那么有深度的程序员,技术牛B这是肯定的了,对技术外的了解超出了我的想象,磊哥看的书很多,涉猎很广泛,尤其在历史和文学方面,聊起天来有理有条、幽默风趣、时不时的引用几句谁谁谁的文章,啊!真感觉不出来是一个技术大牛,更像是罗永浩那样的人,哈哈,在最近2年磊哥就是我的目标,多看书、多讲话,提高自己的表达能力,要不然自己知道的东西不能通过最直接的表达分享出去,这就很郁闷了。
瞎扯了这么多,进入正题吧,今天要说的是一个关于SSI的问题,这里先介绍下SSI
SSI是Server Side Inclde的缩写,就是服务端包含的意思,我今天要说的只是用到了nginx中SSI模块的include命令,这个命令会包含一个页面,然后在nginx服务器中展开。
我遇到的是什么问题呢?现在有个富文本编辑编辑器,要求保存页面篇,输入一些html(包括SSI include命令),然后保存在数据库,保存之后还要求可以编辑,要求富文本编辑器中的内容就像这样内容就像下面这样:
<html> <head> </head> <body> <!--#include virtual="/sinclude/test.shtml"--> <div>Hello World!!!</div> </body> </html>
问题就处在了这里,这里面包含了ssi命令。
这个如果直接访问的只显示Hello World!!!,我们对nginx做如下配置:
ssi on; ssi_types text/html;
这个时候如果有mime type为text/shtml类型的数据通过nginx的时候,nginx就回去解析这些命令,这导致了个问题,我在数据库中查出数据然后返回给客户端富文本编辑器就会出错,我的echo内容如下所示:
<!--# include virtual="/sinclude/test.shtml" --> <!--# include virtual="/sinclude/test1.shtml" --> <!--# include virtual="/sinclude/test2.shtml" -->
页面会显示这种形式:
这我就有点郁闷了,因为服务器上其他功能必须用到ssi,而我这里又不需要,这个该怎么办呢?
这个时候我想到了ssi_types,这里面设置的是text/html,而常用的还有一种text/plain,这种类型的mime是什么呢,在浏览器中他会把所有的内容原封不动的显示出来,不去进行解析html、css。用了这种类型,nginx就不会进行展开了,试试在输出之前修改mime:
header('Content-type: text/plain');
果然,在修改了mime之后,输出和数据库中的一致,原封不动:
看样子问题解决了,但是没想到由于历史原因,后台的编辑框内内容和其他内容是一起返回的,这下囧了,如果设置为text/plain所有的内容都已文本形式显示在浏览器,问题等于还是没有解决~~
这个时候想到nginx配置,由于需要nginx进行解析展开的文件一般为shtml、html等后缀,而查数据库一般为php所以我可以将ssi的所用于缩小为后缀名为shtml、html的文件,看看配置,这里我讲ssi配置信息移动到一个匹配中,再看看效果,
location ~* \.(html|shtml|htm)$ { ssi on; ssi_types text/shtml; proxy_pass http://www.testssi.com; }
新建html、php文件,内容类似,
<?php echo '<!--# include virtual="/sinclude/test.shtml" -->'; echo '<!--# include virtual="/sinclude/test1.shtml" -->'; echo '<!--# include virtual="/sinclude/test2.shtml" -->'; echo 'TEst!!';
html:
<!--# include virtual="/sinclude/test.shtml" --> <!--# include virtual="/sinclude/test1.shtml" --> <!--# include virtual="/sinclude/test2.shtml" --> TEst!!
会发现php访问只输出了Test!!,其他内容要查看源码才可以看见,html中则会进行解析,输出对应包含文件的内容或者没找到报错!!至此问题基本解决了,具体情况下周上班之后试下这个方法,应该没问题,测试的时候都是ok的。
本文版权归作者iforever(luluyrt@163.com)所有,未经作者本人同意禁止任何形式的转载,转载文章之后必须在文章页面明显位置给出作者和原文连接。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To allow the Tomcat server to access the external network, you need to: modify the Tomcat configuration file to allow external connections. Add a firewall rule to allow access to the Tomcat server port. Create a DNS record pointing the domain name to the Tomcat server public IP. Optional: Use a reverse proxy to improve security and performance. Optional: Set up HTTPS for increased security.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

To solve the "Welcome to nginx!" error, you need to check the virtual host configuration, enable the virtual host, reload Nginx, if the virtual host configuration file cannot be found, create a default page and reload Nginx, then the error message will disappear and the website will be normal show.

Converting an HTML file to a URL requires a web server, which involves the following steps: Obtain a web server. Set up a web server. Upload HTML file. Create a domain name. Route the request.

Server deployment steps for a Node.js project: Prepare the deployment environment: obtain server access, install Node.js, set up a Git repository. Build the application: Use npm run build to generate deployable code and dependencies. Upload code to the server: via Git or File Transfer Protocol. Install dependencies: SSH into the server and use npm install to install application dependencies. Start the application: Use a command such as node index.js to start the application, or use a process manager such as pm2. Configure a reverse proxy (optional): Use a reverse proxy such as Nginx or Apache to route traffic to your application

The most commonly used instructions in Dockerfile are: FROM: Create a new image or derive a new image RUN: Execute commands (install software, configure the system) COPY: Copy local files to the image ADD: Similar to COPY, it can automatically decompress tar archives or obtain URL files CMD: Specify the command when the container starts EXPOSE: Declare the container listening port (but not public) ENV: Set the environment variable VOLUME: Mount the host directory or anonymous volume WORKDIR: Set the working directory in the container ENTRYPOINT: Specify what to execute when the container starts Executable file (similar to CMD, but cannot be overwritten)

Yes, Node.js can be accessed from the outside. You can use the following methods: Use Cloud Functions to deploy the function and make it publicly accessible. Use the Express framework to create routes and define endpoints. Use Nginx to reverse proxy requests to Node.js applications. Use Docker containers to run Node.js applications and expose them through port mapping.

To successfully deploy and maintain a PHP website, you need to perform the following steps: Select a web server (such as Apache or Nginx) Install PHP Create a database and connect PHP Upload code to the server Set up domain name and DNS Monitoring website maintenance steps include updating PHP and web servers, and backing up the website , monitor error logs and update content.
