個人練手項目 >_< 簡單的網站開發
首先當您寫好您的django 項目 買好你的服務器 買好你的域名(這裏的域名要進行備案.)
1.準備工作
服務器 windows server 2012 r2(雖然我知道用win的服務器很low,但是其他的我也不會啊!)
python 3.7.4 的準備:
apache 準備:
我用的是 mod_wsgi-4.5.24+ap24vc14-cp37- 從下面的網站下載用pip 安裝 https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
2.萬事具備
我把我的apache 放到了c盤下
web 是我django 放置的地方 我的文件結構目錄
django setting.py 配置
# 好像改的就這麼多
DEBUG = False
ALLOWED_HOSTS = ['hahaaa.cn','localhost','127.0.0.1','www.hahaaa.cn'] # '*',
# 確定靜態文件路徑?_?
STATIC_URL = '/static/'
STATICFILES_DIRS = (
# os.path.join(os.path.dirname(__file__),'..','static').replace('\\',''),
os.path.join(BASE_DIR, 'static'),
# os.path.join('static'),
)
apache 配置
主要配置的文件有 C:\Apache24\conf 文件夾下的 httpd.conf 配置如下 這裏並不是完整的文件信息 只是我進行更改的列出來啦
Define SRVROOT "C:/Apache24"
ServerRoot "C:/Apache24"
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule allowmethods_module modules/mod_allowmethods.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so # https 強轉需要的
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule socache_dbm_module modules/mod_socache_dbm.so # https 強轉需要的
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so # https 強轉需要的
LoadModule ssl_module modules/mod_ssl.so # https 強轉需要的
LoadModule vhost_alias_module modules/mod_vhost_alias.so
<IfModule unixd_module>
User daemon
Group daemon
</IfModule>
# 這個是我的郵箱
ServerAdmin [email protected]
# 網站發佈的端口 只有80端口的才能被收錄 這裏要在防護牆裏加80端口的入站規則
Listen 0.0.0.0:80
ServerName www.hahaaa.cn:80
<Directory />
AllowOverride All
Require all denied
</Directory>
DocumentRoot "C:/Apache24/htdocs"
<Directory "C:/Apache24/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error.log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access.log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "C:/Apache24/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "C:/Apache24/cgi-bin">
AllowOverride All
Options None
Require all granted
</Directory>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
#啓動 httpd-vhosts.conf 配置域名
Include conf/extra/httpd-vhosts.conf
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
# https 強轉需要的 啓動 httpd-ssl.conf
Include conf/extra/httpd-ssl.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
# mod_wsgi 鏈接 在cmd 中輸入 mod_wsgi-express module-config 就可以看到相關路徑啦
LoadFile "c:/users/administrator/desktop/python/python37.dll"
LoadModule wsgi_module "c:/users/administrator/desktop/python/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win32.pyd"
WSGIPythonHome "c:/users/administrator/desktop/python"
WSGIScriptAlias / "C:/web/ChpHahaa/ChpHahaa/wsgi.py"
# 項目目錄
WSGIPythonPath "C:/web/ChpHahaa"
<Directory "C:/web/ChpHahaa/ChpHahaa">
<Files wsgi.py>
Require all granted
</Files>
# 這裏的目的是讓全部網頁http 強轉 https
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</Directory>
# 靜態文件位置
Alias /static "C:/web/ChpHahaa/HLCHP/static"
<Directory "C:/web/ChpHahaa/HLCHP/static">
AllowOverride None
Options None
Require all granted
</Directory>
C:\Apache24\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/web/ChpHahaa"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost-error_log"
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/web/ChpHahaa/ChpHahaa"
ServerName hahaaa.cn
ServerAlias www.hahaaa.cn
ErrorLog "logs/localhost-error_log"
</VirtualHost>
C:\Apache24\conf\extra\httpd-ssl.conf
ServerName www.hahaaa.cn:443
ServerAdmin [email protected]
# 匹配證書 這裏上面要是有相同的屬性名註釋掉
SSLCertificateFile "C:\Apache24\conf\ssl\hahaaa.cn.crt"
SSLCertificateKeyFile "C:\Apache24\conf\ssl\hahaaa.cn.key"
SSLCertificateChainFile "C:\Apache24\conf\ssl\hahaaa.cn_ca.crt"
3.揚帆起航
配置已經配置成功現在進入apache 的bin 文件 啓動 ApacheMonitor.exe
啓動服務 在網頁中輸入 hahaaa.cn
啓動成功!!!