nginx 反向代理實現鏡像網站配置

下面是本人測試的nginx配置文件,沒做註釋,不懂的可看你nginx參數就行(包括單個和集羣)

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

upstream test {
        server  127.0.0.1:80;
    }

upstream test2 {
		server 127.0.0.1:82;
		#server react-china.org;
	}

upstream test3 {
	server 192.168.3.146;
	}

# Default server configuration
server {
        listen 443;
        #自己的域名
        #server_name abc.com;

        root html;
        index index.html index.htm;

        ssl on;
        ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
        ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout 5m;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;
        ssl_prefer_server_ciphers on;

        location / {
           # proxy_pass https://192.168.3.110/;
            #proxy_pass https://zwshd.xyz/;
            
			#proxy_ssl_session_reuse off;
			#proxy_set_header Accept-Encoding deflate;
			#proxy_set_header X-Scheme $scheme;
            #proxy_set_header Host $host:$server_port;
            #proxy_set_header X-Real-IP $remote_addr;
            #proxy_set_header X-Real-PORT $remote_port;
			#proxy_set_header X-HTTPS-Protocol $ssl_protocol;
			#proxy_set_header X-SSL-Protocol $ssl_protocol;
            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #
            	
			# ok
			sub_filter https://www.baidu.com https://127.0.0.1;
			sub_filter_once off;
			proxy_pass https://www.baidu.com;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header Referer https://www.baidu.com;
			proxy_set_header Host www.baidu.com;
			proxy_set_header Accept-Encoding "";
        }
    # 基於URL
    location /110 {
 	      	#proxy_redirect off;
                
		sub_filter_types text/html document script;
                sub_filter https://192.168.3.110 https://192.168.3.114/110;
 
                proxy_set_header Accept-Encoding "";
                sub_filter_once off;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Referer https://192.168.3.114/110;
                proxy_set_header Host 192.168.3.110;
                proxy_pass https://192.168.3.110/;

	}

}

# 基於PORT
server {
    listen 86;
    listen [::]:86;
    root /var/www/html/wzjx/;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

	location / {
            proxy_pass http://test3;
            proxy_set_header Accept-Encoding deflate;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Real-PORT $remote_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    } 
}

# 基於PORT
server {
	listen 85;
	listen [::]:85;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/html/wzjx/;

	# Add index.php to the list if you are using PHP
	index index.php index.html index.htm index.nginx-debian.html;

	server_name _;

	#location / {
        #try_files $uri $uri/ /index.php?$query_string;
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		#try_files $uri $uri/ =404;
	#}

	location / {
			proxy_pass http://test;
			proxy_set_header Accept-Encoding deflate;
	        proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Real-PORT $remote_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}

	# pass PHP scripts to FastCGI server
	#
	location ~ \.php$ {
		fastcgi_pass unix:/var/run/php-fpm.sock;
		fastcgi_index index.php;
		fastcgi_param 	SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#	listen 80;
#	listen [::]:80;
#
#	server_name example.com;
#
#	root /var/www/example.com;
#	index index.html;
#
#	location / {
#		try_files $uri $uri/ =404;
#	}
#}

 

發佈了101 篇原創文章 · 獲贊 16 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章