nginx根据域名动态代理
2015-10-28 00:00
591 查看
多个域名,存在数据库里面,访问到nginx的时候,根据不同域名,反向代理到不同的服务器上
编译nginx的时候要启用 auth_request --with-http_auth_request_module
nginx配置
这里面把asp后缀解析为PHP,会提示Access to the script ‘asp‘ has been denied,把php-fpm 配置文件里面的security.limit_extensions 扩展加上asp 重启服务即可
api.asp 内容
编译nginx的时候要启用 auth_request --with-http_auth_request_module
nginx配置
http { resolver 114.114.114.114; # api返回的地址是域名,提示无法解析时添加该行 auth_request /api.asp; auth_request_set $url $sent_http_url; server { listen 80; server_name localhost; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass $url; } location ~ \.asp$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
这里面把asp后缀解析为PHP,会提示Access to the script ‘asp‘ has been denied,把php-fpm 配置文件里面的security.limit_extensions 扩展加上asp 重启服务即可
api.asp 内容
<?php ob_start(); $domain = substr($_SERVER['HTTP_HOST'],5); $conn = mysql_connect("127.0.0.1","root","password"); if (!$conn) { die('Could not connect: ' . mysql_error()); } mysql_select_db("vpopmail", $conn); $result = mysql_query("select host from tables where domain='".$domain."' limit 1"); while($row=mysql_fetch_array($result)) { $url = "http://".$row['host']; } mysql_close($conn); header("url: $url"); exit(); ?>
相关文章推荐
- keepalived构建LVS_DR和Nginx的高可用集群 推荐
- 记录给nginx增加模块过程中碰到的问题
- libev / libuv / python tornado / nginx 性能比较
- nginx rewite指令模块
- 在Linux和Windows系统上安装Nginx服务器的教程
- Nginx并发连接限制
- 基于nginx的hls直播系统
- Nginx显示目录下的内容、限速
- Nginx做NodeJS应用负载均衡配置实例
- [nginx] 网上最全面nginx教程(近100篇文章整理)
- 106 nginx 405错误解决
- Nginx之location 匹配规则详解
- mac上面启用80端口
- linux下安装 nginx 支持ssl
- linux环境下配置nginx虚拟域名
- mac os x下nginx开机自启动
- 使用nginx负载平衡
- centos下配置nginx支持php
- CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14
- Nginx_修改Web服务器头信息(Header)里的Server值[转]