www.zhblog.net

利用nginx代理解析二级域名

在一台服务器想要部署多个网站应用,需要使用nginx代理:

user  nginx;

worker_processes  1;



error_log  /var/log/nginx/error.log warn;

pid        /var/run/nginx.pid;





events {

    worker_connections  1024;

}





http {

    include       /etc/nginx/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  /var/log/nginx/access.log  main;



    sendfile        on;

    #tcp_nopush     on;



    keepalive_timeout  65;



    #gzip  on;



    #include /etc/nginx/conf.d/*.conf;



    server {

	listen 443 ssl;

	server_name zhblog.net www.zhblog.net m.zhblog.net;

	ssl_certificate /home/zhblog.pem;

	ssl_certificate_key /home/zhblog.key;



	location / {

            # 防爬虫

            if ($http_user_agent ~* (SemrushBot|MJ12bot|java|python) ) {

                access_log off;

                return 403;

            }



	    proxy_set_header Host $host;

	    proxy_set_header X-Real-IP $http_x_forwarded_for;

	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	    proxy_set_header X-Forwarded-Host $host:443;

	    proxy_set_header X-Forwarded-Server $host;

	    proxy_set_header X-Forwarded-Port 443;

	    proxy_set_header X-Forwarded-Proto https;

	    proxy_read_timeout 300s;

		

	    if ($host = 'read.epubmobi.cc' ){

	        proxy_pass http://127.0.0.1:8080;

	    }

	    proxy_pass http://127.0.0.1:80;

	}

    }  



}


 

 

 

展开阅读全文

评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 心情