魏长东

weichangdong

nginx 代理proxy_pass

upstream wcd {
    server  127.0.0.1:8080;
		    keepalive  15;
}
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    location ~ wcd.html$ {
		#return 200 'wcd';
        proxy_pass   http://wcd;
		proxy_connect_timeout   1;
		proxy_set_header  Connection  "Keep-Alive";
		proxy_set_header  Proxy-Connection  "Keep-Alive";
		proxy_redirect  on;
    }
}

server {
    listen       8080;
    server_name  127.0.0.1;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/wcd/;
        index  index.html index.htm;
    }
}


在我本地配置了hosts

192.168.150.128 www.wcd.com

访问http://www.wcd.com/wcd.html 就会跳到8080端口那个nginx配置。

因为我没有安装php,所以就用html做了测试。

等我 搞完这个,突然明白了,其实每次配置php-fpm也是一样的道理。把请求定向到9000的php-fpm去了。

一般的nginx 关于php的配置 这样 和我上面配置的wcd代理是一回事。

#location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}