python - 使用 python 脚本在 apache2 上不通过 SSL 显示图像

标签 python html ssl apache2

我知道这个问题已经被问过好几次了,但我完全没有想法,到处都在阅读这个问题。

我正在运行 Ubuntu 17.04 和 Apache 2.4.25 来托管网络服务器。我已经生成了自己的 SSL 证书。由于这样做,我无法通过 SSL 查看任何图像。目前,我可以确认路径有效,文件完好无损,URL 正确,因为我可以在浏览器中输入 http URL 来访问它。

如果我在加载我的网站时转到网络检查器,如果我点击任何图像,它会给我一个 404 错误。

如何让这些图像通过 SSL 加载。

我的 apache2 配置是:

<VirtualHost *:80>

    ServerName localhost
    ServerAdmin info@****.com
    DocumentRoot /var/www/****.com/pay
    Redirect /secure https://****.com/  


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


</VirtualHost>


<VirtualHost *:443>
    SSLEngine On
    SSLCertificateFile /etc/ssl/certs/****.com.crt
    SSLCertificateKeyFile /etc/ssl/private/****.com.key
    SSLCACertificateFile /etc/ssl/certs/ca-certificates.crt

    SetEnv SECRET_KEY ****
    SetEnv PUBLISHABLE_**** 
    ServerAdmin info@****.com
    ServerName www.****.com
    DocumentRoot /var/www/****.com/pay/static

    WSGIDaemonProcess webtool threads=5 python-path=/var/www/****.com/pay
    WSGIScriptAlias / /var/www/****.com/pay/webtool.wsgi
    EnableMMAP off
    EnableSendfile off
    <Directory /var/www/****.com/pay>
    Options +ExecCGI
    WSGIProcessGroup webtool
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptReloading On
    AllowOverride All
    Require all granted
    </Directory>
</VirtualHost> 

我有一个 python 脚本正在运行来执行我的路线:

    import os
    import stripe
    import cgi
    print "Context-type: text/html"

    from flask import Flask, render_template, request, redirect, send_from_directory
    from flask import request
    from flask import json

    stripe_keys = {
        'secret_key': os.environ['SECRET_KEY'],
        'publishable_key': os.environ['PUBLISHABLE_KEY']
    }

    stripe.api_key = stripe_keys['secret_key']

    app = Flask(__name__, static_url_path='')

    @app.route('/')
    def index():
        return render_template('index.html', key=stripe_keys['publishable_key'])


    @app.route("/hello")
    def hello():
        return "Hello World!"

    if __name__ == "__main__":
        app.run(host="127.0.0.1", port="5050")

    @app.route("/charge", methods=['POST'])
    def charge():
         # Amount in cents
        amount = 500

        customer = stripe.Customer.create(
        email=request.form['stripeEmail'],
        source=request.form['stripeToken']
        )

        charge = stripe.Charge.create(
            customer=customer.id,
            receipt_email=request.form['stripeEmail'],
            amount=amount,
            currency='usd',
            description='Donation'
        )

        return render_template('charge.html', amount=amount)

如果我需要在我的 python 脚本中设置一个路由以允许获取图像,或者我遗漏了其他东西,我无法确定。

我在我的 index.html 文件中调用图像:

“img”文件夹与 index.html 位于同一位置。请帮忙。

最佳答案

你的图像请求正在发送到 WSGI,如果你想让 Apache 处理它们,你将不得不“撤消”/的 WSGIScriptAlias。

我不是 WSGI 用户,但看起来你可以阻止它 通过将其放入您的虚拟主机来有条件地运行:

RewriteEngine ON
RewriteRule ^/img/ - [L]

即使这是空操作,它也应该阻止这部分 WSGi 运行。

关于python - 使用 python 脚本在 apache2 上不通过 SSL 显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44871314/

相关文章:

html - 图像 Sprite 不显示

html - CSS/HTML 菜单 - 无法关闭 iOS 上的菜单

javascript - 将日历移到菜单栏前面

c - 任何允许与服务器直接通信的 C 中的 HTTP 库?

python - 在python中将float转换为不带点/逗号的字符串

python - 如何保存最佳验证分数结果,即保存 6 个分割中的第 5 个分割

python - 使用 python 的 readline 处理带引号的行

python - 通过从第一个列表中获取第一项和从第二个列表中获取最后一项来创建新列表

objective-c - 信任 SSL 证书

node.js - 如何为任何请求禁用 SSL 验证?