Home  >  Article  >  PHP Framework  >  How to solve the problem that thinkphp ip port cannot be accessed

How to solve the problem that thinkphp ip port cannot be accessed

PHPz
PHPzOriginal
2023-04-11 15:09:401117browse

Recently, when using the thinkphp framework to develop a project, I encountered a problem: the IP port cannot be accessed. After some investigation, it was found that the problem was caused by nginx configuration problem. This article will introduce in detail how to solve this problem.

Let’s first look at the specific problem manifestations. Enter http://ip address:port number on the web page, the page keeps loading, and finally displays the error message "Unable to connect to the server". At this point, the first thing we have to do is to check whether the server configuration is correct.

  1. Confirm server port

First, we need to confirm whether the server is listening on the port we specified. You can use the following command to check:

$ netstat -tunlp | grep 端口号

If the port number can be found, it means that the port is already occupied, otherwise the port is not configured correctly.

  1. Check the firewall configuration

If the port is already occupied, then we need to check the firewall configuration. Some security settings will prohibit access to certain ports, causing us to be unable to access specified ports. You can use the following command to view:

$ firewall-cmd --list-all

This command will list all open ports. If the port we specify is not found, then you need to add a firewall rule to allow access.

  1. Check nginx configuration

If there is no problem with the firewall, then you need to check whether the nginx configuration is correct. Usually we need to first access the public IP address of the server to determine whether it can be accessed. If it can be accessed, then you need to check whether the listening IP address and port are correctly specified in the nginx configuration file.

In the nginx configuration file, you need to set the listening address and port. The correct setting method is as follows:

server {
    listen       端口号;
    server_name  客户端IP地址;
    location / {
        root 资源目录;
        index  index.html index.htm;
    }
}

The "port number" and "client IP address" need to be filled in according to the actual situation.

  1. Check php-fpm configuration

If the above steps do not solve the problem, then you need to check whether the php-fpm configuration is correct. php-fpm is a PHP interpreter responsible for converting PHP code into code that can be executed by the server. If php-fpm is not configured correctly, an inaccessible error will occur.

In the configuration file of php-fpm, you need to set the listening address and port. The correct setting method is as follows:

listen = 客户端IP地址:端口号

If we set localhost or 127.0.0.1 in the nginx configuration file, then the listening address of php-fpm also needs to be modified accordingly.

Summary:

When using the thinkphp framework, there may be many reasons why the IP port cannot be accessed, but the most common problem is one of the above four aspects. If you also encounter this problem, you can follow the above steps to troubleshoot. I hope it can help you.

The above is the detailed content of How to solve the problem that thinkphp ip port cannot be accessed. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn