国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Apache > 正文

centos7 apache httpd安裝和配置django項目

2024-08-27 18:29:16
字體:
來源:轉載
供稿:網友
centos7 apache httpd安裝和配置django項目一、安裝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.CUOXin.com/starof/p/4685132.html有問題歡迎與我討論,共同進步。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 花莲县| 民乐县| 盐城市| 富平县| 新民市| 安岳县| 安康市| 天峻县| 遵义县| 宿州市| 井冈山市| 聂拉木县| 石门县| 玉溪市| 洱源县| 武山县| 泾源县| 延川县| 闵行区| 西藏| 兴仁县| 崇文区| 吉隆县| 阿坝| 东至县| 龙口市| 甘孜县| 山阳县| 枣庄市| 通辽市| 西丰县| 龙游县| 司法| 宣恩县| 分宜县| 汉中市| 全椒县| 普兰店市| 离岛区| 襄樊市| 修水县|