{"id":583,"date":"2013-09-11T10:55:57","date_gmt":"2013-09-11T13:55:57","guid":{"rendered":"http:\/\/blog.abratel.com.br\/?p=583"},"modified":"2013-09-11T10:58:00","modified_gmt":"2013-09-11T13:58:00","slug":"proxy-reverso-com-apache-freebsd","status":"publish","type":"post","link":"https:\/\/blog.abratel.com.br\/?p=583","title":{"rendered":"Proxy Reverso com Apache FreeBSD"},"content":{"rendered":"<p><strong>1 &#8211; Alguns par\u00e2metros adicionados em \/usr\/local\/etc\/apache22\/httpd.conf<\/strong><br \/>\nLoadModule xml2enc_module     libexec\/apache22\/mod_xml2enc.so<br \/>\nLoadModule proxy_html_module  libexec\/apache22\/mod_proxy_html.so<\/p>\n<p>ServerName *:80<br \/>\n# Local que estar\u00e3o os vhosts<br \/>\nInclude etc\/apache22\/extra\/httpd-vhosts.conf<\/p>\n<p><strong>2 &#8211; Arquivo \/usr\/local\/etc\/apache22\/extra\/httpd-vhosts.conf<\/strong><br \/>\nNameVirtualHost *:80<br \/>\nAddDefaultCharset Off<br \/>\nServerTokens ProductOnly<br \/>\ninclude &#8220;\/usr\/local\/etc\/apache22\/vhosts.d\/*.conf&#8221;<\/p>\n<p><strong>3 &#8211; Escolhi trabalhar dessa forma pois terei vhosts diferentes, ou seja, tratarei as entradas de forma diferete. Exemplo, quando acessarem teste1.dominio.com.br ir\u00e1 ser direcionado para um servidor e teste2.dominio.com.br ser\u00e1 encaminhado a outro servidor e assim por diante.. Nesse diret\u00f3rio \/usr\/local\/etc\/apache22\/vhosts.d\/ colocaremos todos nossos virtualhosts:<\/strong><\/p>\n<p><strong>A &#8211;<\/strong> (root@proxy-reverso)~# ls \/usr\/local\/etc\/apache22\/vhosts.d\/<br \/>\n       _default.conf   teste2.dominio.com.br  teste1.dominio.com.br<\/p>\n<p><strong>B &#8211;<\/strong> (root@proxy-reverso)~# cat  \/usr\/local\/etc\/apache22\/vhosts.d\/_default.conf<br \/>\n<VirtualHost _default_:80><br \/>\n        HostnameLookups Off<\/p>\n<p>    # needed for named virtual hosts<br \/>\n        UseCanonicalName Off<\/p>\n<p>    # configures the footer on server-generated documents<br \/>\n        ServerSignature Off<br \/>\n<\/VirtualHost><\/p>\n<p><strong>C &#8211; <\/strong>(root@proxy-reverso)~# cat \/usr\/local\/etc\/apache22\/vhosts.d\/teste1.dominio.com.br.conf<br \/>\n<VirtualHost *:80><\/p>\n<p>        ServerAdmin meu_email@dominio.com.br<br \/>\n        ServerName teste1.dominio.com.br<br \/>\n        #Em ON ele vai preservar o endere\u00e7o do host que est\u00e1 fazendo o proxy e n\u00e3o daquele da diretiva ProxyPass<br \/>\n        ProxyPreserveHost       On<br \/>\n        #Em Off evita que usem seu servidor para relay de spammer<br \/>\n        ProxyRequests           Off<br \/>\n        Include \/usr\/local\/etc\/apache22\/sites\/teste1.conf<br \/>\n        # ver os hostnames em seus logs ao inv\u00e9s de endere\u00e7os de ip deixe on<br \/>\n        HostnameLookups Off<br \/>\n        # needed for named virtual hosts<br \/>\n        UseCanonicalName Off<br \/>\n       # configures the footer on server-generated documents<br \/>\n        ServerSignature Off<br \/>\n        ErrorLog &#8220;\/var\/log\/apache\/teste1.dominio.com.br.error_log&#8221;<br \/>\n        CustomLog &#8220;\/var\/log\/apache\/teste1.dominio.com.br.access_log&#8221; common<br \/>\n# M\u00f3dulo deflate \u00e9 usado para comprimir as p\u00e1ginas, ele negocia com os clientes uma compress\u00e3o e envia os dados compactados gerando muito menos tr\u00e1fego na rede<br \/>\n        <IfModule mod_deflate.c><br \/>\n                AddOutputFilterByType DEFLATE text\/html text\/plain text\/xml text\/css text\/javascript application\/x-javascript application\/xml application\/xhtml+xml &#8220;application\/x-javascript \\n\\n&#8221; &#8220;text\/html \\n\\n&#8221;<br \/>\n                DeflateCompressionLevel   9<br \/>\n        <\/IfModule><\/p>\n<p><\/VirtualHost><\/p>\n<p><strong>D &#8211; <\/strong>(root@proxy-reverso)~# cat \/usr\/local\/etc\/apache22\/sites\/teste1.conf<br \/>\nSSLProxyEngine on<\/p>\n<p>        ProxyPass               \/                    http:\/\/servidor1\/<br \/>\n        ProxyPassReverse        \/                    http:\/\/servidor1\/<br \/>\n        Loglevel notice<\/p>\n<p>        ProxyPass               \/o_que_quero\/                    http:\/\/servidor1\/link1\/<br \/>\n        ProxyPassReverse        \/o_que_quero\/                    http:\/\/servidor1\/link1\/<\/p>\n<p><strong>E &#8211; Realizar seguindo o exemplo acima para o teste2.dominio.com.br<\/strong><br \/>\n(root@proxy-reverso)~# cat \/usr\/local\/etc\/apache22\/vhosts.d\/teste2.dominio.com.br.conf<br \/>\n<VirtualHost *:80><br \/>\n        ServerAdmin meu_email@dominio.com.br<br \/>\n        ServerName teste2.dominio.com.br<br \/>\n        ProxyPreserveHost       On<br \/>\n        ProxyRequests           Off<br \/>\n        Include \/usr\/local\/etc\/apache22\/sites\/teste2.conf<br \/>\n        HostnameLookups Off<br \/>\n        UseCanonicalName Off<br \/>\n        ServerSignature Off<br \/>\n        ErrorLog &#8220;\/var\/log\/apache\/teste2.dominio.com.br.error_log&#8221;<br \/>\n        CustomLog &#8220;\/var\/log\/apache\/teste2.dominio.com.br.access_log&#8221; common<br \/>\n<\/VirtualHost><\/p>\n<p><strong>F &#8211; <\/strong> (root@proxy-reverso)~# cat \/usr\/local\/etc\/apache22\/sites\/teste2.conf<br \/>\n#SSLProxyEngine off<br \/>\n        ProxyPass               \/                    http:\/\/servidor2\/<br \/>\n        ProxyPassReverse        \/                    http:\/\/servidor2\/<\/p>\n<p><strong>G &#8211;<\/strong> service apache22 restart<\/p>\n<p><strong>H &#8211;<\/strong> (root@proxy-reverso)~# cat \/etc\/hosts<br \/>\n::1                     localhost localhost.my.domain<br \/>\n127.0.0.1               localhost localhost.my.domain<br \/>\n192.168.218.125         proxy-reverso<br \/>\n192.168.218.204         servidor1<br \/>\n192.168.218.203         servidor2<\/p>\n<p><strong>I &#8211; Testar abrindo no browser<\/strong><br \/>\nhttp:\/\/teste2.dominio.com.br\/o_que_quero\/ &#8211;> ter\u00e1 que abrir o conte\u00fado do http:\/\/servidor1\/link1\/<br \/>\nhttp:\/\/teste1.dominio.com.br\/  &#8211;> ter\u00e1 que abrir o conte\u00fado do http:\/\/servidor2<\/p>\n<p><strong>Notas:<\/strong><\/p>\n<p>1 &#8211; Lembrar de colocar o barra &#8220;\/&#8221; no final dos endere\u00e7os;<br \/>\n2 &#8211; N\u00e3o \u00e9 necess\u00e1rio configura\u00e7\u00f5es no servidor1 e nem no servidor2 apenas o apache funcionando corretamente juntamente com os links necess\u00e1rios;<br \/>\n3 &#8211; Direcionar o dom\u00ednio teste1.dominio.com.br e teste2.dominio.com.br para o ip fixo do servidor;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 &#8211; Alguns par\u00e2metros adicionados em \/usr\/local\/etc\/apache22\/httpd.conf LoadModule xml2enc_module libexec\/apache22\/mod_xml2enc.so LoadModule proxy_html_module libexec\/apache22\/mod_proxy_html.so ServerName *:80 # Local que estar\u00e3o os vhosts Include etc\/apache22\/extra\/httpd-vhosts.conf 2 &#8211; Arquivo \/usr\/local\/etc\/apache22\/extra\/httpd-vhosts.conf NameVirtualHost *:80 AddDefaultCharset Off ServerTokens ProductOnly include &#8220;\/usr\/local\/etc\/apache22\/vhosts.d\/*.conf&#8221; 3 &#8211; Escolhi trabalhar dessa forma pois terei vhosts diferentes,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,2],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/583"}],"collection":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=583"}],"version-history":[{"count":2,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":585,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions\/585"}],"wp:attachment":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}