Configure the LANMP Environment (7)--Configure the Nginx reverse proxy, and configure the Apache virtual host

Source: Internet
Author: User

First, configure Nginx reverse proxy

1. Modify the configuration file

vim/etc/nginx/nginx.conf
add content under 35 lines of http: /data/nginx/vhosts/*. conf;include/etc/nginx/upstream.conf;

2. Create a new upstream.conf file in the/etc/nginx/directory

Vim upstream.conf
Upstream dev.test1.com {server127.0.0.1(Switch to virtual machine IP):8080weight=4max_fails=2fail_timeout=10s;ip_hash;} Upstream dev,test2.com{Server127.0.0.1(Switch to virtual machine IP):8080weight=4max_fails=2fail_timeout=10s;ip_hash;} Upstream dev.test3.com{Server127.0.0.1(Switch to virtual machine IP):8080weight=4max_fails=2fail_timeout=10s;ip_hash;}

3. Create a new proxy.conf in the/etc/nginx/directory

Vim proxy.conf
writes the following:proxy_redirect off;proxy_set_header Host $host;p roxy_set_header X-real-IP $remote _addr;proxy_set_header X-forwarded-For $proxy _add_x_forwarded_for;proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_ 504;proxy_max_temp_file_size0;p roxy_connect_timeout -;p roxy_send_timeout -;p roxy_read_timeout -;p roxy_buffer_size 4k;proxy_buffers432k;proxy_busy_buffers_size 64k;proxy_temp_file_write_size 64k;

4. Create a new test.conf configuration file in the/data/nginx/vhosts/directory

mkdir -p/data/nginx/vhosts

Mkdir-p/data/nginx/logs

Cd/data/nginx/vhosts

Vim test.conf

 write the following content:

  

server {

Listen 80;

server_name dev.test1.com;

CharSet UTF-8;

Access_log/data/nginx/logs/test1.access.log combined;

Location/{

Proxy_pass http://dev.test1.com;

#Header

Include "/etc/nginx/proxy.conf";

}

Error_page 404/error.html;

Location =/error.html {

root/usr/share/nginx/html;

}

# REDIRECT Server error pages to the static page/50x.html

#

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

server {

Listen 80;

server_name dev.test2.com;

CharSet UTF-8;

Access_log/data/nginx/logs/test2.access.log combined;

Location/{

Proxy_pass http://dev.test2.com;

#Header

Include "/etc/nginx/proxy.conf";

}

Error_page 404/error.html;

Location =/error.html {

root/usr/share/nginx/html;

}

# REDIRECT Server error pages to the static page/50x.html

#

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

server {

Listen 80;

server_name dev.test3.com;

CharSet UTF-8;

Access_log/data/nginx/logs/test3.access.log combined;

Location/{

Proxy_pass http://dev.test3.com;

#Header

Include "/etc/nginx/proxy.conf";

}

Error_page 404/error.html;

Location =/error.html {

root/usr/share/nginx/html;

}

# REDIRECT Server error pages to the static page/50x.html

#

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

Second, configure Apache virtual host

1. loading the virtual host configuration file

vim/etc/httpd/conf/httpd.conf
Add the following to the lowest file:include conf/extra/httpd-vhosts.conf

2. Create a new extra directory under the/etc/httpd/conf/directory and create a new httpd-vhosts.conf configuration file in the extra directory

cd/etc/httpd/conf/mkdir/etc/httpd/conf/extravim httpd-vhosts.conf

Add the following content:

<virtualhost 127.0.0.1 (Switch to Virtual machine IP):8080>

ServerAdmin "[Email protected]"

DocumentRoot "/data/www/test1"

ServerName dev.test1.com

Errorlog "/data/httpd/logs/test1.net-error.log"

Customlog "/data/httpd/logs/test1.net-access.log" common

<directory "/" >

Options FollowSymLinks

AllowOverride All

Order Deny,allow

Require all granted

</Directory>

<directory ". Git" >

Deny from all

Require all denied

</Directory>

</VirtualHost>

<virtualhost 127.0.0.1 (Switch to Virtual machine IP):8080>

ServerAdmin "[Email protected]"

DocumentRoot "/data/www/test2"

ServerName dev.test2.com

Errorlog "/data/httpd/logs/test2.net-error.log"

Customlog "/data/httpd/logs/test2.net-access.log" common

<directory "/" >

Options FollowSymLinks

AllowOverride All

Order Deny,allow

Require all granted

</Directory>

<directory ". Git" >

Deny from all

Require all denied

</Directory>

</VirtualHost>

<virtualhost 127.0.0.1 (Switch to Virtual machine IP):8080>

ServerAdmin "[Email protected]"

DocumentRoot "/data/www/test3"

ServerName dev.test3.com

Errorlog "/data/httpd/logs/test3.net-error.log"

Customlog "/data/httpd/logs/test3.net-access.log" common

<directory "/" >

Options FollowSymLinks

AllowOverride All

Order Deny,allow

Require all granted

</Directory>

<directory ". Git" >

Deny from all

Require all denied

</Directory>

</VirtualHost>

2. Create the logs folder below/data/httpd/

cd/data/httpd/mkdir logs

3. Configure IP Resolution for window, open the Hosts file under C:\WINDOWS\SYSTEM32\DRIVERS\ETC and add the following three lines.

192.168. 116.128 (Switch to Virtual machine IP) dev.test1.com 192.168. 116.128 (Switch to virtual machine IP) dev.test2.com
192.168. 116.128 (Switch to virtual machine IP) dev.test3.com

4. Add project directory and test file

Mkdir-p/data/www/test1
Mkdir-p/data/www/test2
Mkdir-p/data/www/test3

Cd/data/www/test1
Vim index.php

Enter the content before the following dashed line:
<?php
echo "Test1";
-------------------------------------------------

Cd/data/www/test2
Vim index.php

Enter the content before the following dashed line :
<?php
echo "Test2";
-------------------------------------------------

Cd/data/www/test3
Vim index.php

Enter the following:
<?php
echo "Test3";

Third, check the configuration success or not

After all configured to restart Nginx and Apache, if the restart failure can use the command status Nginx "httpd", or journalctl-xe see there is a problem.

Common reasons for startup failure:

1. the logs directory or other critical directory is not created.

2. firewall disabled 8080 Port

If all goes well, the full configuration succeeds: The page that corresponds to the content of the/data/www/test1/index.php file appears in the browser access dev.test1.com.

Configure the LANMP Environment (7)--Configure the Nginx reverse proxy, and configure the Apache virtual host

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.