Nginx reverse proxy parse PHP LAMP environment

1.Nginx acts as an intermediary, will forward the request to the other LAMP

192.168.200.112 in yum install LAMP

[root@localhost ~]# yum -y install httpd mairadb mariadb-server php php-mysql

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start mariadb

[root @ localhost ~] # vim /var/www/html/test.php      // add test document

192.168.200.111 install nginx

[root @ localhost ~] # vim /usr/local/nginx/conf/nginx.conf   // modify the main configuration file, add location

  location ~* \.php$ {
  proxy_pass http://192.168.200.112;
  }

[root@localhost ~]# 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 @ localhost ~] # killall -HUP nginx    // restart

Testing in a Web page

 

 

 

 111/112 in the same test results forwarded success

2.Nginx by FPM module, call PHP environment

[root @ nginxetc] # vim /usr/local/nginx/conf/nginx.conf       // modify the main configuration file, add location

server {

...... // omit some of the information

  location / {

              root   html;

  index  index.php index.html index.htm;

          }

  location ~ \ .php $ {                                    Configuration section of the page php // access

  HTML root;                                            // PHP web document root directory

  127.0.0.1:9000 fastcgi_pass;         // PHP-FPM listen address

  fastcgi_indexindex.php;                 // PHP page file

  fastcgi.conf the include;                        // sample configuration comprising fastcgi.conf

  }

}

[root @ nginx ~] # CAT /usr/local/nginx/html/php.php  // create test documents

<?php

phpinfo();

?>

 

 

testing successfully

Guess you like

Origin www.cnblogs.com/zhiyuan-yu/p/11525536.html