Difference between revisions of "Httpd"

From Colettapedia
Jump to navigation Jump to search
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
==httpd.conf==
+
==General==
===Virtual Hosts===
+
* Basically, fuck apache, [[nginx]] is WAY better
 +
* [https://httpd.apache.org/docs/2.4/mod/core.html Apache server core feeatures and directives]
 +
* <code>/sbin/apachectl</code> - Apache HTTP Server Control Interface
 +
** start
 +
** stop
 +
** restart
 +
** fullstatus
 +
** status
 +
** graceful
 +
** graceful-stop
 +
** configtest
 +
** stop
 +
==Map URLs to file Location==
 +
* [https://httpd.apache.org/docs/2.4/urlmapping.html URL mapping docs]
 +
* Set DocumentRoot
 +
 
 +
==Virtual Hosts==
 
* [https://httpd.apache.org/docs/2.4/vhosts/index.html Virtual Host documentation]
 
* [https://httpd.apache.org/docs/2.4/vhosts/index.html Virtual Host documentation]
 
* [https://httpd.apache.org/docs/2.4/vhosts/examples.html Virtual Host examples]
 
* [https://httpd.apache.org/docs/2.4/vhosts/examples.html Virtual Host examples]
 
* "The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com and company2.example.com) on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user."
 
* "The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com and company2.example.com) on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user."
===Configuring reverse proxy===
+
* [https://httpd.apache.org/docs/2.4/mod/core.html#virtualhost VirtualHost directive]
 +
** Contains directives that apply only to a specific hostname or IP address
 +
** Each Virtual Host must correspond to a different IP address, different port number, or a different host name for the server
 +
** VirtualHost directive only valid in server config context, not allowed to next virtualhosts.
 +
 
 +
<pre>
 +
 
 +
<VirtualHost 10.1.2.3:80>
 +
  ServerAdmin webmaster@host.example.com
 +
  DocumentRoot "/www/docs/host.example.com"
 +
  ServerName host.example.com
 +
  ErrorLog "logs/host.example.com-error_log"
 +
  TransferLog "logs/host.example.com-access_log"
 +
</VirtualHost>
 +
 
 +
</pre>
 +
 
 +
==mod_proxy==
 
* [https://httpd.apache.org/docs/2.4/mod/mod_proxy.html mod_proxy] - Multi-protocol proxy/gateway server
 
* [https://httpd.apache.org/docs/2.4/mod/mod_proxy.html mod_proxy] - Multi-protocol proxy/gateway server
* rstudio.conf
+
* A reverse proxy is activated using the ProxyPass directive or the [P] flag to the RewriteRule directive
 +
* Different from a forward proxy which is the standard thing you already know: make my ip look to the website as if it's the server's ip. Here it's make the server's ip look like the proxy's ip
 +
===Reverse Proxy directives===
 +
* <Proxy> - Container for directives applied to proxied resources. Directives placed in <Proxy> sections apply only to matching proxied content.
 +
* ProxyPass - Maps remote servers into the local server URL-space
 +
** This directive allows remote servers to be mapped into the space of the local server.
 +
** The local server does not act as a proxy in the conventional sense but appears to be a mirror of the remote server.
 +
** The local server is often called a reverse proxy or gateway.
 +
** The path is the name of a local virtual path
 +
** url is a partial URL for the remote server and cannot include a query string.
 +
** You can also use a UNIX socket as a valid destination by prepending with unix:
 +
* ProxyPassReverse - When the backend server redirects to another backend url, it will rewrite that to look like proxy url
 +
<pre>
 +
ProxyPass        "/mirror/foo/" "http://backend.example.com/"
 +
ProxyPassReverse  "/mirror/foo/" "http://backend.example.com/"
 +
ProxyPassReverseCookieDomain  "backend.example.com"  "public.example.com"
 +
ProxyPassReverseCookiePath  "/"  "/mirror/foo/"
 +
</pre>
 +
===rstudio.conf example===
  
 
<pre>
 
<pre>
Line 23: Line 74:
  
 
</pre>
 
</pre>
 +
 +
==mod_rewrite==
 +
* RewriteEngine on
 +
** Enables or disables runtime rewriting engine
 +
** Note that rewrite configurations are not inherited by virtual hosts. This means that you need to have a RewriteEngine on directive for each virtual host in which you wish to use rewrite rules.
 +
* RewriteBase
 +
 +
<pre>
 +
DocumentRoot "/var/www/example.com"
 +
AliasMatch "^/myapp" "/opt/myapp-1.2.3"
 +
<Directory "/opt/myapp-1.2.3">
 +
    RewriteEngine On
 +
    RewriteBase "/myapp/"
 +
    RewriteRule "^index\.html$"  "welcome.html"
 +
</Directory>
 +
</pre>
 +
 +
* [https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriterule RewriteRule]
 +
** Defines rules for the rewriting engine
 +
** Syntax: <code>RewriteRule Pattern Substitution [flags]</code>
 +
 +
==mod_alias==
 +
* RedirectMatch
 +
** Sends an external redirect based on a regular expression match of the current URL
 +
** syntax <code>RedirectMatch [status] regex URL</code>

Latest revision as of 15:29, 27 August 2019

General

Map URLs to file Location

Virtual Hosts

  • Virtual Host documentation
  • Virtual Host examples
  • "The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com and company2.example.com) on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user."
  • VirtualHost directive
    • Contains directives that apply only to a specific hostname or IP address
    • Each Virtual Host must correspond to a different IP address, different port number, or a different host name for the server
    • VirtualHost directive only valid in server config context, not allowed to next virtualhosts.

<VirtualHost 10.1.2.3:80>
  ServerAdmin webmaster@host.example.com
  DocumentRoot "/www/docs/host.example.com"
  ServerName host.example.com
  ErrorLog "logs/host.example.com-error_log"
  TransferLog "logs/host.example.com-access_log"
</VirtualHost>

mod_proxy

  • mod_proxy - Multi-protocol proxy/gateway server
  • A reverse proxy is activated using the ProxyPass directive or the [P] flag to the RewriteRule directive
  • Different from a forward proxy which is the standard thing you already know: make my ip look to the website as if it's the server's ip. Here it's make the server's ip look like the proxy's ip

Reverse Proxy directives

  • <Proxy> - Container for directives applied to proxied resources. Directives placed in <Proxy> sections apply only to matching proxied content.
  • ProxyPass - Maps remote servers into the local server URL-space
    • This directive allows remote servers to be mapped into the space of the local server.
    • The local server does not act as a proxy in the conventional sense but appears to be a mirror of the remote server.
    • The local server is often called a reverse proxy or gateway.
    • The path is the name of a local virtual path
    • url is a partial URL for the remote server and cannot include a query string.
    • You can also use a UNIX socket as a valid destination by prepending with unix:
  • ProxyPassReverse - When the backend server redirects to another backend url, it will rewrite that to look like proxy url
ProxyPass         "/mirror/foo/" "http://backend.example.com/"
ProxyPassReverse  "/mirror/foo/" "http://backend.example.com/"
ProxyPassReverseCookieDomain  "backend.example.com"  "public.example.com"
ProxyPassReverseCookiePath  "/"  "/mirror/foo/"

rstudio.conf example


    <VirtualHost *:80>

      <Proxy *>
        Allow from localhost
      </Proxy>

      ProxyPass        /rstudio/ http://localhost:8787/
      ProxyPassReverse /rstudio/ http://localhost:8787/
      RedirectMatch permanent ^/rstudio$ /rstudio/

    </VirtualHost>

mod_rewrite

  • RewriteEngine on
    • Enables or disables runtime rewriting engine
    • Note that rewrite configurations are not inherited by virtual hosts. This means that you need to have a RewriteEngine on directive for each virtual host in which you wish to use rewrite rules.
  • RewriteBase
DocumentRoot "/var/www/example.com"
AliasMatch "^/myapp" "/opt/myapp-1.2.3"
<Directory "/opt/myapp-1.2.3">
    RewriteEngine On
    RewriteBase "/myapp/"
    RewriteRule "^index\.html$"  "welcome.html"
</Directory>
  • RewriteRule
    • Defines rules for the rewriting engine
    • Syntax: RewriteRule Pattern Substitution [flags]

mod_alias

  • RedirectMatch
    • Sends an external redirect based on a regular expression match of the current URL
    • syntax RedirectMatch [status] regex URL