Ubuntu Apache 2.4 配置-HTTPS、python mod WSGI
来源:互联网 发布:湖南 福建卓知 编辑:程序博客网 时间:2024/06/04 18:54
- 配置环境
- 配置HTTPS
- 证书申请可选
- 添加域名ssl配置文件
- 重定向http至https可选
- 配置python运行环境
- 安装mod_wsgi
- 修改配置文件
- 测试WSGI
- 参考链接
配置环境
- Ubuntu 16.04,Apache 2.4
- 域名
www.example.com
Apache2 虚拟站点配置可参考上篇Apache2 虚拟站点配置
本文主要参考资料来自互联网,加以整理修改以符合需求
配置HTTPS
1.证书申请<可选>
参考链接Let’s Encrypt 证书自动化申请
git clone https://github.com/certbot/certbot.git# 临时关闭Apache 2等占用443端口程序,工具需要绑定到443端口service apache2 stop# DNS解析要申请域名到该台服务器# 确认解析正确后开始申请cd certbot-master/./certbot-auto certonly --standalone --email admin@example.com -d example.com# 申请的证书文件在/etc/letsencrypt/live/www.example.com/下
2.添加域名ssl配置文件
创建配置文件/etc/apache2/sites-available/www.example.com.ssl.conf
# 以默认SSL配置文件为模板 cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/www.example.com.ssl.conf
更改配置文件内容为以下
<IfModule mod_ssl.c> <VirtualHost _default_:443> ServerName www.example.com DocumentRoot /var/www/html/www.example.com # 禁止通过浏览器直接访问Log文件 <Files ~ ".log"> Order allow,deny Deny from all </Files> ErrorLog /var/www/html/www.example.com/error.log CustomLog /var/www/html/www.example.com/access.log combined SSLEngine on SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem # 看自己申请的证书是否包含,可选 SSLCertificateChainFile /etc/letsencrypt/live/www.example.com/fullchain.pem </VirtualHost></IfModule>
启用配置文件
a2enmod ssla2ensite www.example.com.ssl.confservice apache2 restart
测试访问https://www.example.com
3.重定向http至https<可选>
添加如下内容到配置文件/etc/apache2/sites-available/www.example.com.conf
# 该配置文件填入www.example.com.conf配置# 而不是www.example.com.ssl.conf配置RewriteEngine OnRewriteCond %{HTTPS} offRewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
启用配置
# 启用rewrite模块a2enmod rewriteservice apache2 restart
测试访问http://www.example.com,检测是否重定向到https
配置python运行环境
安装mod_wsgi
apt-get install libapache2-mod-wsgi
修改配置文件
添加如下内容到配置文件/etc/apache2/sites-available/www.example.com.ssl.conf
# 添加以下内容到<VirtualHost></VirtualHost>中WSGIScriptAlias / /var/www/html/www.example.com/wsgi.py
* 重启apache2*
service apache2 restart
测试WSGI
创建/var/www/html/www.example.com/wsgi.py
import syssys.path.append('/var/www/html/www.example.com/wsgi.py')def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]
访问www.example.com,检验Python是否运行正确
运行错误日志可在/var/www/html/www.example.com/error.log中查看
参考链接
- Apache2 https重定向
- Apache2 mod_wsgi
- Let’s Encrypt 证书申请
阅读全文
0 0
- Ubuntu Apache 2.4 配置-HTTPS、python mod WSGI
- Ubuntu 16.04中 Django + apache + wsgi 配置
- ubuntu下部署wiki与Django (使用mod-python与mod-wsgi)
- ubuntu apache配置https
- Windows+Python+Apache+wsgi
- Ubuntu下配置Apache HTTPS
- Ubuntu下配置Apache HTTPS
- Window + Apache + WSGI 配置
- wsgi+apache配置
- apache+wsgi+flask配置
- Django + Apache + wsgi配置和环境搭建(ubuntu)
- apache mod-python
- flask+mod-wsgi+apache在WINDOWS下的部署
- apache+wsgi+python如何工作
- apache+wsgi+python如何工作
- apache+wsgi+python如何工作
- apache+wsgi+python如何工作
- Apache wsgi Flask配置细节
- 网络请求——————AsyncTask——————深入理解AsyncTask的工作原理
- python调用shell命令之三大方法
- Spark中的Pi Estimation
- redis学习笔记三(列表)
- Apache和Apache Tomcat的区别是什么?
- Ubuntu Apache 2.4 配置-HTTPS、python mod WSGI
- Java基础(二)条件语句
- java.util.Scanner
- JVM中Perm区持续上涨问题
- php获取post参数的几种方式
- 安全通信与安全通信标准EN50159
- SpringMvc restful调用url 及 .do调用配置及区别
- C++全局构造与析构底层实现
- 最大子数组问题