centos7安装httpd服务
来源:互联网 发布:淘宝海外版app 编辑:程序博客网 时间:2024/06/11 00:12
centos7安装httpd服务
一、安装httpd服务
apache在centos7中是Apache HTTP server。如下对httpd的解释就是Apache HTTP Server。所以想安装apache其实是要安装httpd。
httpd.x86_64 : Apache HTTP Server
安装:
# yum install httpd
设置httpd服务开机启动
[root@yl-web httpd]# /sbin/chkconfig httpd onNote: Forwarding request to 'systemctl enable httpd.service'.ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
启动httpd服务
[root@yl-web httpd]# /sbin/service httpd startRedirecting to /bin/systemctl start httpd.service
访问ip验证一下,成功!
二、配置
httpd默认的配置文件目录为
[root@yl-web httpd]# cd /etc/httpd/[root@yl-web httpd]# lsconf conf.d conf.modules.d logs modules run
主配置文件是/etc/httpd/conf/httpd.conf。
配置存储在的/etc/httpd/conf.d/目录。
1、主配置文件
看一下主配置文件httpd.conf里有用的配置项
#服务器根目录ServerRoot "/etc/httpd"#端口#Listen 12.34.56.78:80Listen 80#域名+端口来标识服务器,没有域名用ip也可以#ServerName www.example.com:80#不许访问根目录<Directory /> AllowOverride none Require all denied</Directory># 文档目录DocumentRoot "/var/www/html"# 对 /var/www目录访问限制<Directory "/var/www"> AllowOverride None # Allow open access: Require all granted</Directory># 对/var/www/html目录访问限制<Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory># 默认编码AddDefaultCharset UTF-8#EnableMMAP offEnableSendfile on# include进来其它配置文件IncludeOptional conf.d/*.conf
2、下载配置mod_wsgi
安装mod_wsgi前先进行apache的apxs扩展
http-devel 是为了apxs,yum后你可以whereis apxs去寻找他,然后后边编译使用。
# yum install -y httpd-devel
下载
[root@yl-web collectedstatic]# yum install mod_wsgi
在httpd.conf中增加下面配置:
LoadModule wsgi_module modules/mod_wsgi.so
该配置用来连接django.wsgi,使工程被apache加载。
配置django wsgi
在项目目录下新建wsgi,里面新建django.wsgi,内容如下
import osimport sysimport django.core.handlers.wsgifrom django.conf import settings# Add this file path to sys.path in order to import settingssys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))os.environ['DJANGO_SETTINGS_MODULE'] = 'lxyproject.settings'sys.stdout = sys.stderrDEBUG = Trueapplication = django.core.handlers.wsgi.WSGIHandler()
配置wsgi时,
- 必须配置项目路径到系统路径中,因为要通过项目路径找到settings.py配置文件。也就是sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))。
- DJANGO_SETTINGS_MODULE必须指向项目的settings.py文件。
修改了wsgi的配置后必须重启httpd服务。
3、配置django项目虚拟主机
在/etc/httpd/conf.d中添加配置文件lxyproject.conf,内容如下
<VirtualHost *:80>WSGIScriptAlias / /srv/lxyproject/wsgi/django.wsgiAlias /static/ /srv/lxyproject/collectedstatic/ServerName 10.1.101.31#ServerName example.com#ServerAlias www.example.com<Directory /srv/lxyproject/collectedstatic> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory><Directory /srv/lxyproject/wsgi/> Require all granted</Directory>ErrorLog /etc/httpd/logs/lxyproject.error.logLogLevel warn</VirtualHost>
其中
WSGIScriptAlias 直接告诉apache,这个虚拟主机中,请求/就交给WSGI处理,也就是项目中配置的django.wsgi会指明。
Alias 说明访问/static/直接从DocumentRoot中获取,而无需经过WSGI处理。
现在就可以通过apache服务器配置的IP访问django项目了。
三、资源链接
How to use django with mod_wsgi
本文作者starof,因知识本身在变化,作者也在不断学习成长,文章内容也不定时更新,为避免误导读者,方便追根溯源,请诸位转载注明出处:http://www.cnblogs.com/starof/p/4685132.html有问题欢迎与我讨论,共同进步。
阅读全文
0 0
- centos7安装httpd服务
- 【CentOs7.x】- 安装httpd服务
- centos7 安装httpd
- CentOS7系统操作httpd服务
- CentOS7系统操作httpd服务
- Linux安装HTTPD服务
- liunx安装httpd服务
- httpd 服务安装
- Centos7+httpd+fastcgi+rails安装
- centos7安装配置apache/httpd
- centos7编译安装httpd-2.4
- httpd服务安装以及常见问题
- CentOS7.0安装Apache服务器httpd
- CentOS7.0安装Apache服务器httpd
- CentOS7.2配置Apache服务(httpd)--上篇
- Centos7安装Redis服务
- CentOS7安装FTP服务
- Centos7安装SSDB服务
- Oracle定义varchar2()类型存储汉字的长度问题
- [MyEclipse手册]设置或关闭断点调试自动跳入debug模式
- [Unity&小技巧]快速跳转到 类 的文件
- 在共享DLL中使用MFC与在静态库中使用MFC的区别
- 细说websocket
- centos7安装httpd服务
- 浅谈我对机器学习的理解
- 测试
- POJ 1905 Expanding Rods 笔记
- Http协议
- 2017.06.06回顾 三种构造dataframe的方法 多重共线性开坑
- java实现一个窗口
- java 异常:无法从套接字获取更多数据
- 大数据时代户外广告可以玩什么?