搭建Apache服务器
步骤如下:
一.hosts配置:
1.用编辑器打开hosts文件,位置:C:\Windows\System32\drivers\etc目录下
2.在hosts文件里添加自己的域名配置,配置规则如下:
127.0.0.1 localhost 打开此行即可用localhost访问
127.0.0.1 域名1
127.0.0.1 域名2
..........
配置完后,保存即可,可能需要管理员权限才能修改此文件。(记住ip地址前的'#'号一定要拿掉)。
二.apache配置:
1.编辑httpd.conf文件,开启虚拟主机,位置:在apache的安装目录,即phpstudy安装目录下的phpStudy\Apache\conf,找到Include conf/extra/httpd-vhosts.conf,去掉前面的#
2.进入开启的虚拟主机文件httpd-vhosts.conf进行域名配置,位置:\phpStudy\Apache\conf\extra目录下
配置规则:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "D:/phpStudy/WWW/要配置域名的项目名"
ServerName 配置的域名
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
主要配置DocumentRoot和ServerName,ServerAdmin、ErrorLog、CustomLog可以不配置,若不配置直接删掉或用#注释掉即可,以上配置的域名均是在hosts中配置的域名,案例如下:
以上配置的均是默认端口80,也可以配置在不同端口,此时访问时域名后需带端口号,配置前需要查看一下端口号的占用情况,不要配置已经被占用的端口号。
查看端口号占用情况:cmd打开命令框输入命令netstat -ano查看,具体可以参考:http://jingyan.baidu.com/article/3c48dd34491d47e10be358b8.html
(若80端口被占用可配置其他端口)配置不同的端口号在上面配置中把端口号改成未占用的端口进行配置外,还要把phpStudy\Apache\conf目录下的httpd.conf文件中监听80端口的信息改成配置的端口:
若想在Apache的配置中隐藏入口文件index.php,即使访问地址:localhost/h5.test.cn/index.php/test/index 简化成 localhost/h5.test.cn/test/index,也可以通过域名配置实现,即如下:
<VirtualHost *:80>
DocumentRoot "D:/phpStudy/WWW/h5.test.cn"
ServerName local.h5.test.cn
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
</VirtualHost>
以上配置都完成后,切记要重启服务器。
搭建nginx服务器
在PHPstudy上搭建还是比较容易的,直接切换就可以了。
在配置表vhosts-conf中:
server {
listen 80;
#填写你所配置的虚拟域名
server_name www.xxxx.com;
#填写网站所在目录 eg:"E:/phpStudy/WWW/wordpress"
root "xxxxxxxx";
location / {
index index.html index.htm index.php;
autoindex on;
# 伪静态配置
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
fastcgi_param TP_ENV sixian;
}
}
host和域名设置什么的跟Apache一样的。
注意:在windows下,nginx配置文件的路径避免出现转义字符,如\n ,\t,\a等。linux则不受影响
来源:oschina
链接:https://my.oschina.net/u/4394481/blog/3321653