Apache - studiofu/brain GitHub Wiki

Quick Start

Install XAMMP in windows for apache testing

https://www.apachefriends.org/index.html

Windows Host File

C:\WINDOWS\system32\drivers\etc\hosts

Reverse Proxy

Enable Modules

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Create Virtual Host

<VirtualHost *:80>
	ServerName test1.local
	ProxyRequests off
	ProxyVia Off
	ProxyPreserveHost On
	AllowEncodedSlashes NoDecode

	<Proxy *>
		Order allow,deny
		Allow from all
	</Proxy>

ProxyPass /demo/ http://127.0.0.1:8080/demo/ nocanon
ProxyPassReverse /demo/ http://127.0.0.1:8080/demo/

#ProxyPass / http://127.0.0.1:8080/demo/
#ProxyPassReverse / http://myserverurl.org:8080/myapplication/

</VirtualHost>

Enable SSL

single command to generate self signed certificate

openssl req -x509 -nodes -sha256 -days 365 -newkey rsa:2048 -keyout private.key -out private.crt

change the apache ssl configuration file

Listen 443

and set the private key and also the crt

<VirtualHost _default_:443>

DocumentRoot "C:/xampp/htdocs"
ServerName www.example.com:443
ServerAdmin [email protected]
ErrorLog "C:/xampp/apache/logs/error.log"
TransferLog "C:/xampp/apache/logs/access.log"

SSLEngine on

#   Server Certificate:
SSLCertificateFile "conf/ssl.crt/private.crt"

#   Server Private Key:
SSLCertificateKeyFile "conf/ssl.key/private.key"

<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/xampp/apache/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

CustomLog "C:/xampp/apache/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>   

SSL Reverse Proxy

Similar to non-SSL page and just need to set the ProxyPass in the httpd-ssl.conf VirtualHost Section

    ProxyPass /demo http://127.0.0.1:8080/
    ProxyPassReverse /demo http://127.0.0.1:8080/

Pass the original client ip address by X-Forwarded-For environment variable

https://stackoverflow.com/questions/50308561/apache-proxy-pass-origin-ip-address-to-destination

filter client - Apache 2.4 透過 X-Forwarded-For 阻擋特定 location

https://shazi.info/apache-2-4-%E9%80%8F%E9%81%8E-x-forwarded-for-%E9%98%BB%E6%93%8B%E7%89%B9%E5%AE%9A-location/

Enable Server Side Include

need to add output filter for files

AddOutputFilter INCLUDES .shtml .html

need to enable the modules

LoadModule include_module "{APACHEPATH}/modules/mod_include.so"

need to enable the server side include in the directory by using "Includes"

<VirtualHost 127.0.0.1:80>
	DocumentRoot "{DOCUMENTPATH}/website/"
	ServerName "localost"
	<Directory "{DOCUMENTPATH}/website/">
		AllowOverride All
		Options FollowSymLinks Includes Indexes 
		{ONLINE_MODE}		
	</Directory>
</VirtualHost>

Resources

REVERSE PROXY 反向代理設定

http://blog.davidou.org/archives/1334

Using Jetty with an Apache Proxy

https://help.percussion.com/rhythmyx/implementation/jetty/using-jetty-with-an-apache-proxy.html

Apache as Reverse Proxy with SSL

https://ubuntuforums.org/showthread.php?t=2064909

在Apache上設定安裝SSL憑證(XAMPP)

https://blog.hahasmile.com/%E5%9C%A8apache%E4%B8%8A%E8%A8%AD%E5%AE%9A%E5%AE%89%E8%A3%9Dssl%E6%86%91%E8%AD%89/

⚠️ **GitHub.com Fallback** ⚠️