Apache服务器的配置

主要内容:Windows上Apache虚拟主机的配置、Linux上Https的配置、Apache站点的配置、静态站的配置、Tomcat站点的配置、PHP站点的配置、PythonWeb站点的配置以及域名代理、资源重定位的配置。

Windows配置Apache

编辑httpd.conf文件

方式一:配置虚拟主机

<VirtualHost localhost>
  #ServerAdmin luowei010101@gmail.com
  DocumentRoot "D:/javascript/js_projects"
  #ServerName vvvv.com
  ErrorLog "D:/javascript/js_projects/error.log"
  
  <Directory "D:/javascript/js_projects">
     Options Indexes FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow from all
  </Directory>
</VirtualHost>

方式二:配置目录别名

Alias /js_test/  "D:/javascript/js_projects/test/"
<Directory  "D:/javascript/js_projects/test">
   Options Indexes MultiViews 
   AllowOverride None 
   Order allow,deny 
   Allow from all 
</Directory>

Unbuntu上配置Apache

/etc/apache2/sites-available 添加xxx.conf,比如如下配置:

(https配置) webluowei.com

<VirtualHost *:80> 
     ServerAdmin luowei@webluowei.com
     ServerName webluowei.com
     ServerAlias www.webluowei.com
     DocumentRoot /var/www/webluowei.com
     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined

#     RewriteEngine on
#     RewriteCond %{SERVER_NAME} =webluowei.com [OR]
#     RewriteCond %{SERVER_NAME} =www.webluowei.com
#     RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

#     <FilesMatch "\.(htaccess|php)$">
#        Order allow,deny
#        allow from all
#        ForceType text/plain
#     </FilesMatch>

     Alias /webdav /var/www/webdav
     <Directory /var/www/webdav>
        DAV On
    AuthType Digest
        AuthName "webdav"
        AuthUserFile /etc/apache2/users.password
        Require valid-user

        <Limit GET PUT DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
        Require user luowei
        </Limit>
    AuthDigestDomain / http://webluowei.com/webdav/
        AuthDigestProvider file
    php_value engine off 
        RewriteEngine off
     </Directory>

</VirtualHost>


<IfModule mod_ssl.c>
<VirtualHost *:443>

        ServerAdmin webmaster@localhost
        ServerName webluowei.com
        DocumentRoot /var/www/webluowei.com

        #   SSL Engine Switch:
        #   Enable/Disable SSL for this virtual host.
        SSLEngine on

        #   A self-signed (snakeoil) certificate can be created by installing
        #   the ssl-cert package. See
        #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
        #   If both key and certificate are stored in the same file, only the
        #   SSLCertificateFile directive is needed.
        
    SSLCertificateFile      /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile  /etc/apache2/ssl/apache.key

    #SSLCertificateFile /etc/letsencrypt/live/webluowei.com/cert.pem
    #SSLCertificateFile /etc/letsencrypt/live/webluowei.com/fullchain.pem
    #SSLCertificateKeyFile  /etc/letsencrypt/live/webluowei.com/privkey.pem
    #SSLCertificateChainFile    /etc/letsencrypt/live/webluowei.com/chain.pem


     Alias /webdav /var/www/webdav
     <Directory /var/www/webdav>
        DAV On
        AuthType Digest
        AuthName "webdav"
        AuthUserFile /etc/apache2/users.password
        Require valid-user

        <Limit GET PUT DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
            Require user luowei
        </Limit>
        AuthDigestDomain / http://webluowei.com/webdav/
        AuthDigestProvider file
        php_value engine off
        RewriteEngine off
     </Directory>


</VirtualHost>

</IfModule>

(Tomcat端口转发) my.webluowei.com.conf

<VirtualHost *:80>   
    ServerName my.webluowei.com 
    ProxyIOBufferSize 8192  
    ProxyRequests Off   
    ProxyVia Full   
    ProxyPass / http://webluowei.com:8080/ smax=5 max=20 ttl=120 retry=300   
    ProxyPassReverse / http://webluowei.com:8080/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>  

(域名代理) app.webluowei.com.conf

<VirtualHost *:80>   
    ServerName mybrowser.webluowei.com 
    ProxyIOBufferSize 8192  
    ProxyRequests Off   
    ProxyVia Full   
    ProxyPass / http://app.webluowei.com/ smax=5 max=20 ttl=120 retry=300   

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

(资源目录重定位) life.webluowei.com.conf

<VirtualHost *:80>
    ServerAdmin abc@rootls.com
    ServerName life.webluowei.com
    ServerAlias life.webluowei.com pua.webluowei.com
    
    DocumentRoot /var/www/life.webluowei.com
    <Directory "/var/www/life.webluowei.com">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

(图片资源) img.webluowei.com.conf

<VirtualHost *:80>
    ServerAdmin luowei@webluowei.com
    ServerName img.webluowei.com 
    ServerAlias img.webluowei.com

    # 指定资源目录
    DocumentRoot /var/www/img.webluowei.com
    # 允许跨域访问
    Header set Access-Control-Allow-Origin "*"

    # 配置防盗链
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$ [NC]
    RewriteCond %{HTTP_REFERER} !webluowei.com [NC]
    RewriteCond %{HTTP_REFERER} !rootls.com [NC]
    RewriteCond %{HTTP_REFERER} !baidu.com [NC]
    RewriteCond %{HTTP_REFERER} !google.cn [NC]
    RewriteCond %{HTTP_REFERER} !google.com [NC]
    RewriteRule .*.(js|css|json|txt|doc|pdf|mp3|mp4|zip|rar|bmp|png|jpg|gif)$ http://webluowei.com [R,NC,L]

    # 配置日志生成目录
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

(Python WSGI) user.webluowei.com.conf

<VirtualHost *:80>
        ServerName user.webluowei.com
        WSGIScriptAlias / /var/www/user.webluowei.com/flaskapp.wsgi
        <Directory /var/www/user.webluowei.com/app/>
            Order allow,deny
            Allow from all
        </Directory>
        Alias /static /var/www/user.webluowei.com/app/static
        <Directory /var/www/user.webluowei.com/app/static/>
            Order allow,deny
            Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error_user.webluowei.com.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access_user.webluowei.com.log combined
</VirtualHost>

(PHP bbs) bbs.webluowei.com

<VirtualHost *:80> 
     ServerAdmin webmaster@example.com
     ServerName bbs.webluowei.com
     ServerAlias bbs.webluowei.com
     DocumentRoot /var/www/bbs.webluowei.com
     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

版权所有,转载请注明出处 luowei.github.io.