LNMP Architecture - Nginx parsing PHP related configuration, Nginx agent

Nginx parsing PHP related configuration

configuration file

vim /usr/local/nginx/conf/vhost/test.com.conf
.........
location ~ \.php$
    {
        include fastcgi_params;
        //fastcgi_pass 127.0.0.1:9000
        fastcgi_pass unix:/tmp/php-fcgi.sock;
        //There are two listening formats of fastcgi ﹐ pass, but the format of Nginx and PHP FPM should be consistent
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
    }
............

Note: there are two formats of fastcgi ﹣ u pass, but no matter which format is used, it can ensure that the formats in Nginx and PHP FPM are the same, otherwise an error of 502 will be reported; fastcgi
_The path of the line where param script filename is located should be the same as the root path!

Nginx agent

The Nginx agent is a reverse agent. Reverse Proxy means that the proxy server accepts the connection request on the Internet, then forwards the request to the server on the internal network, and returns the result obtained from the server to the client requesting connection on the Internet. At this time, the proxy server acts as a server externally.

graph LR
User – > proxy server
Proxy servers – > users
Proxy server – > Web server
web server – > proxy server

Enter the virtual host directory

[root@adailinux ~]# cd /usr/local/nginx/conf/vhost/

Create a proxy server

[root@dl-001 vhost]# vim proxy.conf
server
{
    listen 80;
    server_name ask.apelearn.com;
    #Define domain name (generally consistent with the domain name of the proxy ip)
    location /
    {
        proxy_pass      http://121.201.9.155/;
        #Specify the IP (web server IP) of the proxied (accessed)
        proxy_set_header Host   $host;
        #$host refers to the servername of the proxy server (also the domain name of the proxy IP)
        proxy_set_header X-Real-IP      $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Testing

Before agent (not reloaded will not take effect)

[root@dl-001 vhost]# curl -x127.0.0.1:80 ask.apelearn.com/robots.txt
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>

After agency

[root@dl-001 vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@dl-001 vhost]# /usr/local/nginx/sbin/nginx -s reload


[root@dl-001 vhost]# curl -x127.0.0.1:80 ask.apelearn.com/robots.txt
#
# robots.txt for MiWen
#

User-agent: *

Disallow: /?/admin/
Disallow: /?/people/
Disallow: /?/question/
Disallow: /account/
Disallow: /app/
Disallow: /cache/

Keywords: Nginx PHP Web Server vim

Added by phpSensei on Thu, 30 Apr 2020 15:35:29 +0300