
Apache常用命令
查看apache版本 |
启动apache |
重启apache |
关闭apache |
sudo apachectl -v |
sudo apachectl start |
sudo apachectl restart |
sudo apachectl stop |
Apche常用的几个文件和目录
主目录 |
/etc/apache2/ |
默认日志目录 |
/private/var/log/apache2 |
日志1 |
/private/var/log/apache2/mysites-error_log.log |
日志2 |
/private/var/log/apache2/mysites-access_log.log |
主配置文件 |
/etc/apache2/httpd.conf |
虚拟主机文件 |
/etc/apache2/extra/httpd-vhosts.conf |
配置Apache
- 备份主配置文件*/etc/apache2/httpd.conf*备份到任意目录
- 修改主配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| User _www Group _www
User ponyma Group wheel
<Directory /> AllowOverride none Require all denied </Directory>
<Directory /> Require all granted AllowOverride all </Directory>
Include /private/etc/apache2/extra/httpd-vhosts.conf
|
不会用Vi编辑器则直接跳到目录用其他软件编辑。
创建虚拟主机
备份并修改虚拟主机配置文件*/etc/apache2/extra/httpd-vhosts.conf*
打开后有两个默认的配置 将其删除或者注释均可,以下为正常用法例子
一般复制粘贴修改DocumentRoot和ServerName即可
1 2 3 4 5 6 7 8 9 10 11 12
| <VirtualHost *:80> DocumentRoot "/Users/jiaming/Documents/nobige" ServerName nobige.cn ErrorLog "/private/var/log/apache2/sites-error_log" CustomLog "/private/var/log/apache2/sites-access_log" common <Directory /> Options Indexes FollowSymLinks MultiViews AllowOverride None Order deny,allow Allow from all </Directory> </VirtualHost>
|
以下为中文注释和代理用法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <VirtualHost *:80> DocumentRoot "项目文档根目录" ServerName 域名 ErrorLog "/private/var/log/apache2/mysites-error_log" CustomLog "/private/var/log/apache2/mysites-access_log" <Directory "项目文档根目录"> Options FollowSymLinks Multiviews Indexes MultiviewsMatch Any AllowOverride None Require all granted </Directory> <Proxy *> Order deny,allow Allow from all </Proxy>
ProxyPass /web http://example.com/web ProxyPassReverse /web http://example.com/web </VirtualHost>
|
这里值得一提的是不要忘记将域名加入host,还有做完这一切后记得重启或者启动Apache服务器哦!
设置HOST
打开host文件/etc/hosts,加入127.0.0.1 nobige.cn
更多Apache高级的用法请Google或者搜索本博客