ubuntu下apache2 安装 配置 卸载 CGI设置 SSL设置,ubuntuapache2


一、安装、卸载apache2      apache2可直接用命令安装           sudo apt-get install apache2      卸载比较麻烦,必须卸干净,否则会影响apache2再安装      (1)            sudo apt-get --purge remove apache2           sudo apt-get --purge remove apache2.2-common           sudo apt-get autoremove        (2) (关键一步)找到没有删除掉的配置文件,一并删除           sudo find  /etc -name "*apache*" -exec  rm -rf {} \;           sudo rm -rf /var/www      开启/重启apache2服务           service apache2 start/restart           sudo /etc/init.d/apache2 start/restart   二、配置文件      严格来说,apache2的配置文件是/etc/apache2/apache2.conf apache先加载apache2.conf,然后根据apache2.conf里的Include指令载入其他配置文件。      动态模块的配置           Include mods-enabled/*.load           Include mods-enabled/*.conf      用户自己的配置           Include httpd.conf      端口监听的配置           Include ports.conf      一般性的配置语句片断           Include conf.d/      虚拟主机的配置指令           Include sites-enabled/      ubuntu下,web的根目录是在/var/www,设置是在/etc/apache2/sites-enabled/000-default中            DocumentRoot /var/www       <Directory />      Options FollowSymLinks +ExecCGI      AllowOverride None       </Directory>      <Directory /var/www/>      Options Indexes FollowSymLinks MultiViews      AllowOverride None      Order allow,deny      allow from all      </Directory>        web的默认主页是在/etc/apache2/mods-enabled/dir.conf里           DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm        XXX-enabled 和XXX-available目录,XXX-enabled中放的是指向XXX-available中相应文件的符号链接,不过虽然如此,只有用ln命令把XXX-enabled中的文件链接到XXX-enabled中才能起作用。   三、CGI 设置      在/var/www下创建一个目录 cgi-bin,作为cgi程序存放的地点,然后修改配置文件/etc/apache2/sites-enabled/000-default      将           ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/           <Directory "/usr/lib/cgi-bin/">           AllowOverride None           Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch           Order allow,deny           Allow from all           </Directory>      修改为:           ScriptAlias /cgi-bin/ /var/www/cgi-bin/           <Directory "/var/www/cgi-bin">           AllowOverride None           Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch           Order allow,deny           Allow from all           AddHandler cgi-script cgi           </Directory>      重启apache服务      cgi程序的权限必须是755(可运行)。 四、SSL设置      创建SSL目录           sudo mkdir /etc/apache2/ssl      创建自签名凭证,内容随便填           sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt      开启SSL 模块           a2enmod ssl      编辑/etc/apache2/sites-enabled/default-ssl.conf           ServerAdmin webmaster@localhost           ServerName www.unixmen.com:443             SSLEngine on SSLCertificateFile /etc/apache2/ssl/apache.crt           SSLCertificateKeyFile /etc/apache2/ssl/apache.key      启动虚拟主机           a2ensite default-ssl      重启apache           sudo service apache2 restart

相关内容