nginx作为web服务器一个重要的功能就是反向代理。
当然你也可以使用nginx配置正向代理,本是介绍如何配置nginx的反向代理。
nginx反向代理的指令不需要新增额外的模块,默认自带proxy_pass指令,只需要修改配置文件就可以实现反向代理。
配置前的准备工作,后端跑apache服务的ip和端口,也就是说可以通过http://ip:port能访问到你的网站。
然后就可以新建一个vhost.conf,加入如下内容,记得修改ip和域名为你的ip和域名。
修改nginx.conf,添加 include quancha.conf
到http{}段, reload nginx就可以了。
quancha.conf文件如下:
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
|
## Basic reverse proxy server ##
## Apache backend for www.quancha.cn ##
upstream
apachephp
{
server
ip
:
8080
;
#Apache
}
## Start www.quancha.cn ##
server
{
listen
80
;
server_name
www
.
quancha
.
cn
;
access_log
logs
/
quancha
.
access
.
log
main
;
error_log
logs
/
quancha
.
error
.
log
;
root
html
;
index
index
.
html
index
.
htm
index
.
php
;
## send request back to apache ##
location
/
{
proxy_pass
http
:
//apachephp;
#Proxy Settings
proxy_redirect
off
;
proxy_set_header
Host
$
host
;
proxy_set
_header
X
-
Real
-
IP
$
remote_addr
;
proxy_set
_header
X
-
Forwarded
-
For
$
proxy_add_x_forwarded_for
;
proxy_next_upstream
error
timeout
invalid_header
http_500
http_502
http_503
http_504
;
proxy_max_temp_file
_size
0
;
proxy_connect
_timeout
90
;
proxy_send
_timeout
90
;
proxy_read
_timeout
90
;
proxy_buffer
_size
4k
;
proxy
_buffers
4
32k
;
proxy_busy_buffers
_size
64k
;
proxy_temp_file_write
_size
64k
;
}
}
## End www.quancha.cn ##
|
nginx作为web服务器一个重要的功能就是反向代理。
当然你也可以使用nginx配置正向代理,本是介绍如何配置nginx的反向代理。
nginx反向代理的指令不需要新增额外的模块,默认自带proxy_pass指令,只需要修改配置文件就可以实现反向代理。
配置前的准备工作,后端跑apache服务的ip和端口,也就是说可以通过http://ip:port能访问到你的网站。
然后就可以新建一个vhost.conf,加入如下内容,记得修改ip和域名为你的ip和域名。
修改nginx.conf,添加 include quancha.conf
到http{}段, reload nginx就可以了。
quancha.conf文件如下:
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
|
## Basic reverse proxy server ##
## Apache backend for www.quancha.cn ##
upstream
apachephp
{
server
ip
:
8080
;
#Apache
}
## Start www.quancha.cn ##
server
{
listen
80
;
server_name
www
.
quancha
.
cn
;
access_log
logs
/
quancha
.
access
.
log
main
;
error_log
logs
/
quancha
.
error
.
log
;
root
html
;
index
index
.
html
index
.
htm
index
.
php
;
## send request back to apache ##
location
/
{
proxy_pass
http
:
//apachephp;
#Proxy Settings
proxy_redirect
off
;
proxy_set_header
Host
$
host
;
proxy_set
_header
X
-
Real
-
IP
$
remote_addr
;
proxy_set
_header
X
-
Forwarded
-
For
$
proxy_add_x_forwarded_for
;
proxy_next_upstream
error
timeout
invalid_header
http_500
http_502
http_503
http_504
;
proxy_max_temp_file
_size
0
;
proxy_connect
_timeout
90
;
proxy_send
_timeout
90
;
proxy_read
_timeout
90
;
proxy_buffer
_size
4k
;
proxy
_buffers
4
32k
;
proxy_busy_buffers
_size
64k
;
proxy_temp_file_write
_size
64k
;
}
}
## End www.quancha.cn ##
|