apache設置反向代理和nginx設置反向代理

apache配置反向代理

在設置中打開proxy模塊和proxy_http模塊

在ubuntu中使用sudo a2enmod proxysudo a2enmod proxy_http
在windows中使用去掉httpd.conf中的LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_http_module modules/mod_proxy_http.so前的註釋nginx

在配置文件中設置須要配置的參數

在windows中配置httpd.conf文件,在ubuntu中配置site_enabled中具體網站的參數apache

ProxyRequests Off
<Proxy *>
	Require all granted
</Proxy>
ProxyPass /backward http://localhost:7000

nginx設置反向代理

在nginx.conf或者site-enable中配置

server {
        listen       8000;
    #    listen       somename:8080;
        server_name  somename  alias  another.alias;

        location / {
                proxy_pass https://www.piwheels.org;
		proxy_ssl_server_name on;
		proxy_redirect   default;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
    }

proxy_ssl_server_name on;是爲了解決一下問題:ubuntu

SSL_do_handshake() failed (SSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure) while SSL handshaking to upstreamwindows

出現錯誤的緣由:
nginx反向代理的時候默認沒有將 server_name 發給上游服務(被代理的服務)。若是上游服務器配置了多個證書,這會致使上游服務器沒法給出正確的證書來通訊,進而致使握手失敗。開啓proxy_ssl_server_name指令後,nginx在與上游服務進行TLS協商時,會發送server_name。
proxy_redirect default;是爲了解決:
在服務器中有可能會進行403跳轉,打開該設置後,nginx會自動對域名進行替換。服務器

相關文章
相關標籤/搜索