


Research on SSI issues in nginx, Research on nginxSSI issues_PHP tutorial
Research on SSI issues in nginx, research on nginxSSI issues
I feel quite happy recently. No one in this project team specializes in PHP. I am the first one to come in to do PHP ( Of course there is the front end), haha, I will design and modify a PHP framework that suits our business, haha, I feel like I will learn a lot. A few days ago, I talked about the PHP framework in front of more than 20 seniors in the group, and talked with the big guys We are discussing the PHP framework that is suitable for us. I feel that my ability to express myself is too poor. I cannot express clearly what I know. I still need my mentor to help me express it. I would like to thank my mentor Yu Honglei (Brother Lei for short) and Brother Lei. He is simply my idol. I have never seen such a profound programmer. This is for sure that he is a good technician. His understanding of technology is beyond my imagination. Brother Lei has read a lot of books and has a wide range of interests, especially in In terms of history and literature, the chat is organized and humorous, and I quote a few words from someone's article from time to time, ah! I really don’t feel that he is a technical master, more like a person like Luo Yonghao, haha. In the past two years, Brother Lei has been my goal. Read more books, speak more, and improve my ability to express myself. Otherwise, what I know cannot be Sharing it through the most direct expression is very depressing.
After so much nonsense, let’s get to the point. Today I’m going to talk about a question about SSI. Let’s first introduce SSI
SSI is the abbreviation of Server Side Include, which means server side inclusion. What I am going to talk about today is just using the include command of the SSI module in nginx. This command will include a page and then expand it in the nginx server.
What problem am I encountering? Now there is a rich text editor that requires you to save the page, enter some HTML (including the SSI include command), and then save it in the database. After saving, it also requires that it can be edited. The content in the rich text editor is required to be like this. As follows:
<html> <head> </head> <body> <!--#include virtual="/sinclude/test.shtml"--> <div>Hello World!!!</div> </body> </html>
The problem lies here, which contains the ssi command.
If accessed directly, only Hello World will be displayed! ! ! , we configure nginx as follows:
ssi on; ssi_types text/html;
At this time, if there is data with mime type text/shtml passing through nginx, nginx will go back to parse these commands, which causes a problem. I find the data in the database and return it to the client rich text editor. An error will occur. My echo content is as follows:
<!--# include virtual="/sinclude/test.shtml" --> <!--# include virtual="/sinclude/test1.shtml" --> <!--# include virtual="/sinclude/test2.shtml" -->
The page will display this form:
This makes me a little depressed, because other functions on the server must use SSI, but I don’t need it here. What should I do?
At this time, I thought of ssi_types. The setting here is text/html, and there is also a commonly used text/plain. What is this type of mime? In the browser, it will leave all the content intact. It is displayed dynamically without parsing html and css. If this type is used, nginx will not expand. Try modifying the mime before outputting:
header('Content-type: text/plain');
Sure enough, after modifying the mime, the output is consistent with the one in the database and remains unchanged:
It seems that the problem has been solved, but I didn’t expect that due to historical reasons, the content in the background edit box is returned together with other content. This is embarrassing. If it is set to text/plain, all the content will be displayed in text form. Browser, the problem is still not solved~~
At this time, I think of the nginx configuration. Since the files that need to be parsed and expanded by nginx generally have suffixes such as shtml and html, and the query database is usually php, I can reduce the use of ssi to files with suffixes of shtml and html. Take a look at the configuration, here I will move the ssi configuration information into a match, and then look at the effect,
location ~* \.(html|shtml|htm)$ { ssi on; ssi_types text/shtml; proxy_pass http://www.testssi.com; }
Create new html and php files with similar content,
<?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!!
You will find that the php access only outputs Test!!, and other content can only be seen by viewing the source code. In html, it will be parsed, and the content corresponding to the included file will be output or an error will be reported if it is not found! ! At this point the problem has basically been solved. If you try this method after work next week, it should be fine. It was ok during the test.
The copyright of this article belongs to the author iforever (luluyrt@163.com). Any form of reprinting is prohibited without the consent of the author. After reprinting the article, the author and the original text link must be given in an obvious position on the article page.

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.

The start and stop commands of Nginx are nginx and nginx -s quit respectively. The start command starts the server directly, while the stop command gracefully shuts down the server, allowing all current requests to be processed. Other available stop signals include stop and reload.

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 register for phpMyAdmin, you need to first create a MySQL user and grant permissions to it, then download, install and configure phpMyAdmin, and finally log in to phpMyAdmin to manage the database.

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

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.

nginx appears when accessing a website. The reasons may be: server maintenance, busy server, browser cache, DNS issues, firewall blocking, website misconfiguration, network connection issues, or the website is down. Try the following solutions: wait for maintenance to end, visit during off-peak hours, clear your browser cache, flush your DNS cache, disable firewall or antivirus software, contact the site administrator, check your network connection, or use a search engine or web archive to find another copy of the site. If the problem persists, please contact the site administrator.

There are five methods for container communication in the Docker environment: shared network, Docker Compose, network proxy, shared volume, and message queue. Depending on your isolation and security needs, choose the most appropriate communication method, such as leveraging Docker Compose to simplify connections or using a network proxy to increase isolation.
