今天开发几个页面,但是页面中调用了线上的一些http接口进行渲染页面,因为跨域问题,但是又不想弄成jsonp方式,因此弄个apache http server来折腾。这个只适用于linux
1.从apache下载apache httpd
2.下载安装后打开安装目录下conf文件夹的httpd.conf配置文件进行修改
3.首先修改Listen端口比如为8081,修改之后保存(因为可能默认的80端口被占用了,所以修改自己定义的)
Listen 8088
4.打开安装目录下bin文件夹的httpd启动
./httpd -X
5.打开浏览器输入localhost:8088,可以发现会出现It works!提示,这说明启动成功了
但是如果我需要换成我的一些静态html页面和js等,比如我有一个静态页面项目webapp,我放到/usr/local/apache2/webapp(当然自己可以指定放到其他目录)
那么再打开httpd.conf找到如下
DocumentRoot "/usr/local/apache2/htdocs" <Directory "/usr/local/apache2/htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn‘t give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory>
将/usr/local/apache2/htdocs替换为/usr/local/apache2/webapp
DocumentRoot "/usr/local/apache2/webapp" <Directory "/usr/local/apache2/webapp"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn‘t give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory>
保存后,重新启动httpd再访问即可正常访问其他了。
原文:http://my.oschina.net/kittyMan/blog/363491