ngix反向代理

由于公司微信公众号后台开发的需求,需要一个80端口的服务器(微信要求必须80或者443端口),但公司只有一个服务器,80端口公司官网要用,怎么办?只能用反向代理来解决了。

首先安装nginx

安装好了以后,在/etc/nginx目录下,有个配置文件nginx.conf

只需要修改这个配置文件,然后重启nginx就可以了

我把公司官网的apache改成了82端口,微信用的后台改成了9898端口,在阿里云配置了两个域名

www.xx.com,wx.xx.com,反向代理的作用就是让用户访问www域名的80端口的时候转到apache的82端口,访问wx域名的80端口时候,访问9898端口。

其他不多说了,贴配置文件

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
	worker_connections 768;
	# multi_accept on;
}


http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	# gzip_vary on;
	# gzip_proxied any;
	# gzip_comp_level 6;
	# gzip_buffers 16 8k;
	# gzip_http_version 1.1;
	# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	#include /etc/nginx/sites-enabled/*;
	
	    #配置一个代理即tomcat1服务器  
            upstream tomcat_server1 {  
                server 127.0.0.1:9898;  
            }  
              
    	    #配置一个代理即apache2服务器  
            upstream apache_server2 {  
                server 127.0.0.1:82;  
            }  
              
   	 		#配置一个虚拟主机  
            server {  
                listen 80;  
                server_name www.xx.com;  
                location / {  
                        #域名www.xx.com的请求全部转发到tomcat_server1即tomcat1服务上  
                        proxy_pass http://tomcat_server1;  
                        #欢迎页面,按照从左到右的顺序查找页面  
                        index index.jsp index.html index.htm;  
                }
            }  
              
            server {  
                listen 80;  
                server_name wx.xx.com;  
                location / {  
                      #域名wx.xx.com的请求全部转发到apache_server2即apache服务上  
                      proxy_pass http://apache_server2;  
                      index index.jsp index.html index.htm;  
                }  
            }
}


#mail {
#	# See sample authentication script at:
#	# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#	# auth_http localhost/auth.php;
#	# pop3_capabilities "TOP" "USER";
#	# imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#	server {
#		listen     localhost:110;
#		protocol   pop3;
#		proxy      on;
#	}
# 
#	server {
#		listen     localhost:143;
#		protocol   imap;
#		proxy      on;
#	}
#}


最后,执行下nginx -s reload 指令,重新加载一下配置文件就可以了

猜你喜欢

转载自blog.csdn.net/wangpeng2011314/article/details/79160817