zoukankan      html  css  js  c++  java
  • 关于apache配置(虚拟主机 certbot-auto https)

    这个随笔算是做个记录吧,省得以后重蹈覆辙。

    其实重蹈覆辙这事干过太多次,所以现在养成了做笔记得习惯,毕竟记忆有限。

    事出有因,这两天在设置httpd.conf(centos7 httpd)时又浪费了一个多小时。其实本身就是很简单得事。

    默认配置文件为httpd.conf,一般我都是利用find命令搜,find / -name httpd.conf

    这个conf中会有这么两行:

    Include conf.modules.d/*.conf

    IncludeOptional conf.d/*.conf

    所以上级文件夹conf.modules.d和conf.d内的conf文件都是被加载的。

    如果设置虚拟主机配置文件的话,只需在任一文件夹内添加一个conf文件,比如vhost.conf即可。这样做是为了方便管理。

    <VirtualHost *:443>
            ServerName xxx.xx
            ServerAlias xxx.xx
            DocumentRoot "/var/www/html/"
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =xxx.xx
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>

    虚拟主机的配置信息优先级比httpd.conf中直接设置的web端口、目录等信息高。

     配置conf的最终目的是想测试下https,利用的certbot-auto这个免费证书项目(letsencrypt)。

    vhost.conf如下:

    <VirtualHost *:443>
            ServerName xxx.xx:443
            ServerAlias xxx.xx
            DocumentRoot "/var/www/html/"
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =xxx.xx
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/xxx.xx/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/xxx.xx/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/xxx.xx/chain.pem
    
    <IfModule mod_deflate.c>
    DeflateCompressionLevel 7
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
    AddOutputFilter DEFLATE css js html htm gif jpg png bmp php
    </IfModule>
    
    </VirtualHost>
    
    <Directory /var/www/html/xuni>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    vhost-le-ssl.conf:

    <IfModule mod_ssl.c>
    <VirtualHost *:443>
            ServerName xxx.xx
            ServerAlias xxx.xx
            DocumentRoot "/var/www/html/"
    SSLCertificateFile /etc/letsencrypt/live/xxx.xx/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/xxx.xx/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateChainFile /etc/letsencrypt/live/xxx.xx/chain.pem
    </VirtualHost>
    </IfModule>

    这样就ok了。别忘了服务器做端口放行。

    以上是apache的设置。现在我们试试nginx。

  • 相关阅读:
    牛客网 二叉树的镜像 JAVA
    牛客网 反转链表 JAVA
    牛客网 调整数组顺序使奇数位于偶数前面 JAVA
    Integer to Roman LeetCode Java
    Valid Number leetcode java
    Longest Common Prefix
    Wildcard Matching leetcode java
    Regular Expression Matching
    Longest Palindromic Substring
    Add Binary LeetCode Java
  • 原文地址:https://www.cnblogs.com/b1gstar/p/13123649.html
Copyright © 2011-2022 走看看