您的位置:首页 > 运维架构 > Apache

Ubuntu centos系统——apache如何解决跨域资源访问

2017-12-05 10:09 441 查看
参考文档:HTTP://blog.csdn.net/ownfire/article/details/46707229 http://www.mechonomics.com/enabling-cors-cross-origin-resource-sharing-for-apache2-on-ubuntu-12-04/ 1. sudo a2enmod头文件2.sudo gedit  /etc / apache2 / sites-available /000-default.conf编辑添加:LoadModule headers_module modules / mod_headers.so标头集Access-Control-Allow-Origin *如下:<VirtualHost *:80>    LoadTileConfigFile /usr/local/etc/renderd.conf    ModTileRenderdSocketName /var/run/renderd/renderd.sock    LoadModule headers_module modules/mod_headers.so    # Timeout before giving up for a tile to be rendered    ModTileRequestTimeout 0    # Timeout before giving up for a tile to be rendered that is otherwise missing    ModTileMissingRequestTimeout 30    # The ServerName directive sets the request scheme, hostname and port that    # the server uses to identify itself. This is used when creating    # redirection URLs. In the context of virtual hosts, the ServerName    # specifies what hostname must appear in the request's Host: header to    # match this virtual host. For the default virtual host (this file) this    # value is not decisive as it is used as a last resort host regardless.    # However, you must set it for any further virtual host explicitly.    #ServerName www.example.com    ServerAdmin webmaster@ localhost    DocumentRoot / var / www / html    标头集Access-Control-Allow-Origin *    #可用的日志级别:trace8,...,trace1,debug,info,notice,warn,    #错误,暴击,警报,emerg。    #也可以配置特定的日志级别    #模块,例如    #LogLevel info ssl:warn    ErrorLog $ {APACHE_LOG_DIR} /error.log    CustomLog $ {APACHE_LOG_DIR} /access.log合并    #对于来自conf-available /的大多数配置文件,    #在全球范围内启用或禁用,有可能    #仅包含一个特定虚拟主机的行。例如    #下面的行只启用该主机的CGI配置    #在通过“a2disconf”全局禁用之后。    #include conf-available / serve-cgi-bin.conf</虚拟主机>#vim:syntax = apache ts = 4 sw = 4 sts = 4 sr noet3.重启阿帕奇服务apache2重新启动测试跨域访问即可centos系统在httpd.conf里面加这两句就可以使用LoadModule headers_module modules / mod_headers.so标头集Access-Control-Allow-Origin *Apache服务器配置的方法,包括修改服务器配置文件的方法和如何编辑httpd.conf。接下来,通过本文给大家重点讲解,需要的朋友参考下吧1.修改服务器配置文件
2.编辑httpd.conf文件找下面这行,把#去掉,目的是开启Apache的头信息自定义模块
重点内容
意思是对这个域名的资源进行访问时,添加一个头信息最后重启服务器生效二,查看Linux系统版本的命令(3种方法):1,lsb_release -a,即可列出所有版本信息:以root身份登录到服务器,然后重新启动计算机,然后重新启动计算机,然后重新启动计算机。 noarch:printing-4.0-amd64:printing-4.0-noarch分销商编号:CentOS说明:CentOS 6.5(Final)版本:6.5Codename:Final这个命令适用于所有的Linux发行版,包括RedHat,SUSE,Debian等等发行版。2,cat / etc / redhat-release,这种方法只适合Redhat系的Linux:[root @ S-CentOS home]#cat / etc / redhat-releaseCentOS release 6.5(Final)3,cat / etc / issue,此命令也适用于所有的Linux发行版。[root @ S-CentOS home]#cat / etc / issueCentOS release 6.5(Final)Kernel \ r on \ m

centos查看apache用的是哪个httpd.conf

httpd -V
得到类似如下结果:
-D HTTPD_ROOT="/etc/httpd"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
然后,两个拼起来就是你要找的路径
Task: Start Apache 2 Server /启动apache服务# /etc/init.d/apache2 startor$ sudo /etc/init.d/apache2 startTask: Restart Apache 2 Server /重启apache服务# /etc/init.d/apache2 restartor$ sudo /etc/init.d/apache2 restartTask: Stop Apache 2 Server /停止apache服务# /etc/init.d/apache2 stopor$ sudo /etc/init.d/apache2 stop工欲善其事,必先利其器。

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: