2017-07-02 28 views
0

我知道这个问题已经被问过好几次了,但我完全没有想法,并且一直在阅读关于此的所有内容。使用python脚本在apache2上未通过SSL显示的图像

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

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

如何通过SSL加载这些图像?

我的Apache2配置为:

<VirtualHost *:80> 

    ServerName localhost 
    ServerAdmin [email protected]****.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 [email protected]****.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文件与调用图像。请帮忙。

回答

0

您的图片请求正在发送给WSGI,如果您希望Apache处理它们,您必须“撤消”/的WSGIScriptAlias。

我不是一个WSGI用户,但似乎你可以阻止这种情况的 通过把这个在你的虚拟主机运行条件:

RewriteEngine ON 
RewriteRule ^/img/ - [L] 

即使这是一个空操作,它应该阻止这部分来自WSGi的运行。

+0

谢谢您的回复。我认为这可能是这种情况,并做了一些研究如何在我的烧瓶应用程序中提供图像。通过创建一条路径来提供图像,我可以通过SSL访问这些图像。 @ app.route( “/静态/ ”) 高清图像(路径): 返回app.send_static_file(路径) 也道歉。我无法让我的评论将我的文本识别为代码。根据用户指南,我尝试了缩进四个空格。 – samp17