nginx 反代 host 备案
时间:2014-10-12 05:10 来源:linux.it.net.cn 作者:it
公司网站没有在XX云上备案,只好找不用备案的主机做代理。
正常nginx 代理配置写上
proxy_set_header Host $http_host;
但还是提示要备案。
删除这句当然可以,但我也无法知道host了。
解决方法
nginx 可以自定header参数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server {
listen 80;
server_name www.hello.com;
index index.php;
charset utf-8;
access_log off;
location / {
proxy_redirect off ;
#proxy_set_header Host $http_host;
proxy_set_header td_http_host $http_host;
#自定义header用来传递 $http_host
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http:
//122
.122.122.122:2233;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
server {
listen 80;
server_name localhost;
index index.php;
charset utf-8;
root
/home/wwwroot/src
;
#access_log logs/access_www.hello.com.log myformat;
#我配置日志一般用域名来区分日志,因为我这儿一个网站可能有N个域名,只好改为动态哈。
#当然要设置下nginx log目录权限与当前nginx进程用户相同如配置下
# chown www:www /usr/local/nginx/log -R
access_log logs
/access_
${http_td_http_host}.log myformat;
# 再送上我日志格式myformat 反代专用版
# log_format myformat '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for" '
# '$request_time';
#设置为 on,允许读取自定义header
underscores_in_headers on;
location
/mytest
{
echo
$http_td_http_host;
#就是代理上配置的"td_http_host" 自定header
}
location ~ \.php$ {
#还可以通过 fastcgi_param 传递给fastcgi
#这样我就可以在php中用 $_SERVER['TD_HTTP_HOST'] 取到值了。
fastcgi_param td_http_host $http_td_http_host;
fastcgi_pass my_php_fpm;
fastcgi_index index.php;
include fastcgi.conf;
}
}
(责任编辑:IT)
公司网站没有在XX云上备案,只好找不用备案的主机做代理。
正常nginx 代理配置写上 proxy_set_header Host $http_host; 但还是提示要备案。 删除这句当然可以,但我也无法知道host了。 解决方法 nginx 可以自定header参数
(责任编辑:IT) |