• 关于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。

  • 相关阅读:
    Ubuntu16.04编译Android6.0/cm13.0教程及相关错误解决办法
    TWRP基于omnirom 6.0.1编译教程
    教你一招:解决Win 10安装软件时提示:文件系统错误 (-1073740940)
    红米3 TWRP-3.0.2(android_6.0.1_r72分支)中文版Recovery更新于20161018
    C# Note32: 查漏补缺
    postgreSQL使用杂谈
    Granfana+PostgreSQL
    WIndows下使用Grafana+InfluxDB打造监控系统
    【译】历史上的名人如何利用不同的思维方式成就自己
    【译】Focused and Diffuse Modes(专注与发散模式)
  • 原文地址:https://www.cnblogs.com/b1gstar/p/13123649.html
Copyright © 2020-2023  润新知