nginx reverse proxy for IPv6 proxy IPv4web

1, after the environment is ready, download the installation package

Enter a directory (just a directory can be used to store the downloaded installation package Nginx, here in the / root directory, for example)

Enter the directory command: cd / root

Nginx download the installation package, this use case nginx-1.16.0 (latest version is available through the official website - http://nginx.org/download to view )

Download command: wget http://nginx.org/download/nginx-1.16.0.tar.gz

 2,解压Nginx的tar包

Unzip command: tar -zxvf ./nginx-1.16.0.tar.gz

3, to see if decompression success

Command: ls

4, into the newly unpacked directory

Command: cd nginx-1.16.0

Configuration (in this case the mounting point Nginx / usr / local / nginx / directory)

命令: ./configure --prefix=/app/nginx/

5, compile and install

命令: make && make install

6, the entire verification, compilation, the installation process should not report anything wrong, if you use the prefix set in a target directory during installation, you also need to set the environment variable in the / etc / profile file (Note: The environment variable generally refers to operating system is used to specify the parameters of the operating system environment, the software equivalent of a boot is provided (e.g. mysql / jdk) fast path, etc., user-friendly.)

Command: vi / etc / profile

In most added at the end of export PATH = / app / nginx / sbin: $ PATH (where # add nginx path to comment suggested adding)

7, so that the environment variables to take effect

Command: source / etc / profile

8, with the export command to view the environment variables found to have just set up Nginx directory has been successfully into the

9, check whether the installation was successful:

Into the etc directory (cd / etc) execute the command: nginx -t, if correct will be given the appropriate error message

10, Nginx configuration file to configure the location Nginx configuration file: /app/nginx/conf/nginx.conf (exact location depends on your own if you do not know where to put the configuration file, you can use xftp view) , using vi command editing:

we /usr/local/nginx/conf/nginx.conf

11, the configuration file to modify the configuration files are installed in the conf directory nginx.conf, command Nginx:

/usr/local/nginx/sbin/nginx -c /app/nginx/conf/nginx.conf

12, start nginx, command:

nginx

13, see the Nginx status command:

ps -ef | grep nginx

14 test, in the case of an externally accessible start Nginx browser address just configured in the configuration file, as shown, that is success

Problems that may arise:

When using an external browser, access the address is likely not to visit.

Cause of the problem: There is no open port 80, or a firewall is not closed

For security reasons, it is recommended to select 80 ports open

1, open port 80 (please note that at this time to make sure the firewall is turned on. Otherwise, this step does not make sense):

Command to view open ports in the firewall - iptables -L

A port (80 in this example) open firewall-cmd --zone = public --add-port = 80 / tcp --permanent

Restart the firewall: systemctl restart firewalld.service

2, turn off the firewall:

service firewalld stop

These two operations, one to select. So far, Nginx installation tutorial.

In nginx compiled nginx.conf installation package file as follows:

http {

upstream ipv6 {# ipv6 is the name of the upstream server to create their own

server 1.1.1.1:80; # 1.1.1.1 is the IP address of the real site of IPv4

}

……

……

……

server {

    listen       80 default_server ;

    listen    [::]:80 default_server ; #增加该命令,即监听所有IPv6的80端口

    server_name  xxxx.yyyy.edu.cn;  #IPv4的url

……

……

……

location / {

         proxy_pass  http://ipv6;  #该部分所有的红颜色为添加的,需要关联upstream和server信息

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        root   html;

        index  index.html index.htm;

    }

After installation, enable nginx service, you can be tested.

Add plurality of agents as follows:

http {

   map $host $upstream{

   www.aaaa.edu.cn 1.1.1.1:80;

   www.bbbb.edu.cn 2.2.2.2:80;

   www.cccc.edu.cn 3.3.3.3:80;

include mime.types;

default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

server {

   listen     80;

   listen   [::]:80;

   server_name www.aaaa.edu.cn;

   location / {

          proxy_pass http://www.aaaa.edu.cn; #上海民航职业

         proxy_set_header Host $host;

         proxy_set_header X-Real-IP $remote_addr;

         proxy_set_header X-Forwarded-For $http_x_forwarded_for;

      root  html;

      index  index.html index.htm;

   }

}

server {

   listen     80;

   listen   [::]:80;

   server_name www.bbbb.edu.cn;

   location / {

          proxy_pass http://www.bbbb.edu.cn; #上海出版印刷

         proxy_set_header Host $host;

         proxy_set_header X-Real-IP $remote_addr;

         proxy_set_header X-Forwarded-For $http_x_forwarded_for;

      root  html;

      index  index.html index.htm;

   }

}

server {

   listen     80;

   listen   [::]:80;

   server_name www.cccc.edu.cn;

   location / {

          proxy_pass http://www.cccc.edu.cn; #上海农林职业

         proxy_set_header Host $host;

         proxy_set_header X-Real-IP $remote_addr;

         proxy_set_header X-Forwarded-For $http_x_forwarded_for;

      root  html;

      index  index.html index.htm;

   }

}

Guess you like

Origin blog.51cto.com/1449587/2457306