windows和mac下分别配置虚拟主机
windows下配置
1.找到apache的配置文件,httpd.conf
2.找到 LoadModule rewrite_module modules/mod_rewrite.so 去掉前边的#
3.找到 Include conf/extra/httpd-vhosts.conf 去掉前边的#
4.找 conf/extra/httpd-vhosts.conf 这个文件
5.加
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin phpexcel@php.com #管理邮箱
DocumentRoot "D:/phpStudy/WWW” #工作目录,也就是代码位置
ServerName www.excel.com #虚拟域名
ErrorLog "logs/dummy-host2.example.com-error.log" //apache中的错误日志
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
6. 在httpd.conf中找
<Directory "D:/phpStudy/WWW"> ----工作目录
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all ---------访问权限
Require all granted
AllowOverride All
Order allow,deny
Allow from all ---------访问权限
Require all granted
</Directory>
7.在hosts中(windows目录 C:\Windows\System32\drivers\etc)加
127.0.0.1 www.excel.com #指向虚拟域名
8.重启apache
访问www目录下的文件可以看到效果
mac nginx配置虚拟主机
1. 打开 /usr/local/etc/nginx/nginx.conf 注意权限,用sudo vi nginx.conf 打开
2. 在http中 最后加上 include vhosts/*.conf;如果有,请忽略,可以第三步了
3. 在 /usr/local/etc/nginx/vhosts 目录下,新建文件,以.com.conf结束,比方说baidu.com.conf,此处命名自己最好以域名命名,因为我们在这个目录下可以配置很多个虚拟主机,一个文件就是一个虚拟主机
4.sudo vi xx.com.conf
5. 注意红色的几处地方就好了
upstream baidu(和文件名相同) {
server 127.0.0.1:80; #自己的ip及端口
}
server {
server {
listen 80;
charset utf-8;
server_name www.baidu.com; #虚拟主机名
#access_log logs/apicloud-access.log ;
#error_log logs/apicloud-error.log ;
root /Users/www; #代码存放目录
if ( $http_cookie ~* "(.*)$")
{
set $meilishuo_cookie $1;
}
location / {
index index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php last;
}
}
try_files $uri /index.php?$args;
#location /index.php {
location ~* \.php$ {
fastcgi_pass apicloud;
fastcgi_next_upstream error timeout invalid_header http_500;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
{
set $meilishuo_cookie $1;
}
location / {
index index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php last;
}
}
try_files $uri /index.php?$args;
#location /index.php {
location ~* \.php$ {
fastcgi_pass apicloud;
fastcgi_next_upstream error timeout invalid_header http_500;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
}
6.配hosts,打开 /etc/hosts,用命令sudo vi /etc/hosts
7. 加上dns解析 127.0.0.1 www.baidu.com
8.重启nginx (sudo pkill -9
/usr/local/opt/nginx/bin 重启命令 sudo nginx
/usr/local/opt/nginx/bin)
然后访问对应目录 /Users/www 下的php文件就可以了