Nginx-NGINX怎么配置反向代理

Nginx-NGINX怎么配置反向代理

清晨说ぺ晚安 发布于 2017-08-29 字数 674 浏览 1077 回复 1

NGINX怎么配置反向代理

自己试验了一下二级个性域名的配置:

server { 
listen 80;
server_name www.dewen.net.cn;
location / {
root /data/www;
index index.html;
}
}

server {
listen 80;
server_name *.dewen.net.cn;
root /data/vhost;
location ~ ^/(images|styles)/
{
proxy_redirect off;
proxy_set_header Host www.dewen.net.cn;
proxy_pass http://127.0.0.1:80;
}
location / {
set $username default;
if ( $http_host ~* "^(.*).dewen.org$") {
set $username $1;
}
rewrite ^/(.*) /user/space/$username/$1 last;
}
}

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚风撩人 2017-09-26 1 楼

这个我以前的一份:

server
{
listen 80;
server_name www.huacha.com;
index index.php index.html index.htm;
root /home/wwwroot/www.huacha.com;

location / {
try_files $uri @apache;
}

location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include proxy.conf;
#proxy_redirect default;
}

location ~ .*.(php|php5)?$
{
proxy_pass http://127.0.0.1:88;
include proxy.conf;
#proxy_redirect default;
}

location /status {
stub_status on;
access_log off;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*.(js|css)?$
{
expires 12h;
}

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
}
proxy.conf
proxy_connect_timeout 30s;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 32k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;