nginx1.15 Reverse Proxy:
Forward Proxy:
The user establishes a connection with the proxy server using a browser. Proxy server to find the Web server.
The proxy server is set in the client browser.
Reverse proxy:
The user establishes a connection to the reverse proxy server. The reverse proxy server proxies the request to the back-end Web server.
The reverse proxy server is configured on the server side of the proxy. The commonly used reverse proxy is: Nginx.
System Environment: centos7.5
Installation Environment:
Service Name |
Service IP Address |
Service description |
Node01
|
18.18.23.109 |
nginx1.15 |
Node02 |
18.18.23.110 |
mysql5.7.22 |
Node03
|
18.18.23.111 |
tomcat8/php7.1.2 |
One. Nginx Reverse proxy Tomcat:
1.nginx Reverse proxy tomcat configuration:
NGINX.CONF configuration:
HTTP segment configuration: include vhost/*.conf;
#mkdir vhosts
#vi vhosts/proxy-tomcat.conf
server {Listen 88;server_name tomcat;access_log logs/tomcat-access.log;error_log logs/tomcat-error.log;location/{ Proxy_pass http://18.18.23.111:8080;
Tomcat Server configuration:
Installing jdk1.8
To configure environment variables:
Export java_home=/usr/local/jdk1.8.0_45 export path= $JAVA _home/bin: $PATH export classpath=.: $JAVA _home/lib/dt.jar:$ Java_home/lib/tools.jar
To install the Tomcat server:
Download Tomcat:
#curl-O apache-tomcat-8.5.31.tar.gz https://tomcat.apache.org/download-80.cgi#8.5.31/apache-tomcat-8.5.31.tar.gz
Unzip Tomcat.
Start Tomcat.
./bin/start.sh
Browser access:
http://18.18.23.109:88 , the page for Tomcat is returned.
Second, nginx1.15 reverse proxy php
1. Install third-party libraries that are dependent on PHP:
# yum-y Install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel pcre-devel gd-d Evel Libcurl-devel curl-devel libxslt-devel OpenSSL openssl-devel
2. Compile and install PHP:
# tar -zxvf php-7.1.2.tar.gz#cd php-7.1.2# ./configure --prefix=/usr/local /php7 --with-config-file-path=/usr/local/php/etc --with-mysqli --enable-mysqlnd -- enable-embedded-mysqli --with-curl --with-freetype-dir --with-gd - -with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath -- enable-libxml --enable-inline-optimization --enable-gd-native-ttf -- enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl - -enable-shmop --enable-sOap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --with-jpeg-dir --with-png-dir --with-iconv --with-pcre-dir -- with-mhash #make && make install
3. Copy and modify the configuration file:
On the PHP server, the establishment of Nginx users, to ensure that Nginx server and Nginx User ID number, group ID number consistent.
# CP Php.ini-development/usr/local/php7/etc/php.ini
Configure PHP-FPM
# cp/usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf # cp/usr/local/php7/etc/php-fpm.d/w Ww.conf.default/usr/local/php7/etc/php-fpm.d/www.conf
To modify a configuration file:
# Vim/usr/local/php7/etc/php.ini
Short_open_tag = on default_charset = "UTF-8" Date.timezone = Asia/shanghai
#vim/usr/local/php7/etc/php-fpm.d/www.conf
[www] user = nginx group = nginx listen.owner = nginx listen.group = nginx listen = 18.18.23.111:9000 pm = dynamic pm.max_children = 50 #子进程最大数量 pm.start_ servers = 20 #在启动时创建的子进程数量 pm.min_spare_servers = 5 # minimum number of idle child processes pm.max_spare_servers = 50 # Maximum number of idle child processes pm.process_idle_timeout = 10s # How many seconds after an idle process has been idle php_admin_value[error_log] = /var/log/fpm-php.www.log
4. Start PHP-FPM:
Add As System service:
# Cat/usr/lib/systemd/system/php-fpm.service [Unit] description=php7.1.2 after=network.target [service] T Ype=forking execstart=/usr/local/php7/sbin/php-fpm execstop=/bin/pkill-9 php-fpm PrivateTmp=true [Install] Wantedby=multi-user.target
#systemctl daemon-reload #systemctl Enable PHP-FPM #systemctl start PHP-FPM
5.Nginx Configure PHP program to be forwarded to PHP via fastcgi
# vim/usr/local/nginx/conf/nginx.conf
Configure on the server segment:
Include vhost/*.conf;
# vim/usr/local/nginx/conf/vhost/proxyphp.conf
server { listen 81; Server_name php; access_log logs/php-access.log ; location / { root html/wordpress; index index.php index.html index.htm; } location ~ \.php$ { root html/wordpress; fastcgi_pass 18.18.23.111:9000; #php服务器ip地址. fastcgi_index index.php; fastcgi_param script_filename /scripts$ fastcgi_script_name; include fastcgi.conf; } }
PHP Script Storage location:
# TAR-ZXVF Wordpress-4.9.4-zh_cn.tar.gz-c/usr/local/nginx/html/#chown-R nginx/usr/local/nginx/wordpress
6.mysql configuration:
Mysql> CREATE DATABASE wordpress;mysql> create user ' blog ' @ '% ' identified by ' 123 ';mysql> grant all privileges on wordpress.* to ' blog ' @ '% ';mysql> flush privileges;
Browser access:
http://18.18.23.109:81/index.php
WordPress has been built to complete.
Nginx Reverse proxy tomcat8 and PHP7 (iv)