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

来源:互联网 发布:淘宝生意参谋多少钱 编辑:程序博客网 时间:2024/06/06 03:27
参考文档: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 noet

3.重启阿帕奇
服务apache2重新启动
测试跨域访问即可

centos系统在httpd.conf里面加这两句就可以使用

LoadModule headers_module modules / mod_headers.so

标头集Access-Control-Allow-Origin *


Apache服务器配置的方法,包括修改服务器配置文件的方法和如何编辑httpd.conf。接下来,通过本文给大家重点讲解,需要的朋友参考下吧

1.修改服务器配置文件

1
2
3
4
6
<Directory/www/web/yuming.com/public_html/>
 Options FollowSymLinks
 AllowOverride All
 Require all granted
 HeadersetAccess-Control-Allow-Origin *
</Directory>

2.编辑httpd.conf文件

找下面这行,把#去掉,目的是开启Apache的头信息自定义模块

1
#LoadModule headers_module modules/mod_headers.so

重点内容

1
Access-Control-Allow-Origin *

意思是对这个域名的资源进行访问时,添加一个头信息

最后重启服务器生效


二,查看Linux系统版本的命令(3种方法):

1,lsb_release -a,即可列出所有版本信息:

以root身份登录到服务器,然后重新启动计算机,然后重新启动
计算机,然后重新启动计算机。 noarch:printing-4.0-amd64:printing-4.0-noarch
分销商编号:CentOS
说明:CentOS 6.5(Final)
版本:6.5
Codename:Final

这个命令适用于所有的Linux发行版,包括 RedHat SUSE,Debian等等发行版。

2,cat / etc / redhat-release,这种方法只适合Redhat系的Linux:

[root @ S-CentOS home]#cat / etc / redhat-release
CentOS release 6.5(Final)

3,cat / etc / issue,此命令也适用于所有的Linux发行版。

[root @ S-CentOS home]#cat / etc / issue
CentOS 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 start
or
$ sudo /etc/init.d/apache2 start
Task: Restart Apache 2 Server /重启apache服务
# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart
Task: Stop Apache 2 Server /停止apache服务
# /etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop

工欲善其事,必先利其器。







原创粉丝点击