微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HTTPS 请求未到达 Apache 虚拟主机上的 django 亚马逊 Linux 2

如何解决HTTPS 请求未到达 Apache 虚拟主机上的 django 亚马逊 Linux 2

我正在尝试从同一个 url 托管一个 react 应用程序和一个 django rest api(ribosome.info,如果有帮助,现在就开始……)。我在 /etc/httpd/conf 中有两个虚拟主机配置:一个用于 react,另一个用于 django。我的问题是,当我尝试在端口 ribosome.info:8000 上访问 django 时,服务器给出了来自服务器的空响应:

curl: (52) Empty reply from server

此时我已经尝试了很多事情,但在失败发生时非常茫然。我做过的事情:

  1. 在 AWS 控制台中启用端口 8000(以及大量其他端口)上的流量。
  2. 将 django 的虚拟主机包含在主 httpd.conf 中
  3. 将配置指向 Wsgi 的正确目录:
WsgiScriptAlias / /var/www/backend/rxz_backend/wsgi.py process-group=ribosomeapi
WsgiDaemonProcess ribosomeapi python-path=/var/www/backend python-home=/var/www/venv
WsgiProcessGroup ribosomeapi
  1. 授予对相关文件夹的最大权限并使 apache 成为拥有它们的用户

但是,当尝试从浏览器连接到 ribosome.info:8000 时,它超时并且在本地 curl'ing 只是给出空的答复。有人可以告诉我我错过了什么吗?这是我的 aws 规则:

enter image description here

我之前只设置了一次 apache 虚拟主机,它在不同的发行版上,因此 apache 是 apache2,并且是启用站点等的全部内容。如果我猜想我已经错误地配置了一些 apache 主机。 因此,我的 httpd 配置的文件夹结构是:

/etc/httpd/conf--/
        django.conf
        httpd.conf
        httpd-le-ssl.conf
        magic

主要的apache配置httpd.conf

ServerRoot "/etc/httpd"
Listen 80

<VirtualHost *:80>
    DocumentRoot "/var/www/html"
    ServerName "ribosome.info"
    ServerAlias "www.ribosome.info"
RewriteEngine on
RewriteCond %{SERVER_NAME} =ribosome.info [OR]
RewriteCond %{SERVER_NAME} =www.ribosome.info
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<Directory "/var/www/backend">
    Options Indexes FollowSymLinks
    AllowOverride None
    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" combined
</IfModule>

<IfModule alias_module>
   ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<Directory "/var/www/backend">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<Directory "/var/www/backend">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

<IfModule mod_http2.c>
    Protocols h2 h2c http/1.1
</IfModule>


#IncludeOptional conf.d/*.conf

Include /etc/httpd/conf/httpd-le-ssl.conf
Include /etc/httpd/conf/django-le.conf

<IfModule mod_ssl.c>
Listen 443
</IfModule>
<IfModule mod_ssl.c>
Listen 8000
</IfModule>
 

react 的配置(httpd-le-ssl.conf):

<IfModule mod_ssl.c>
<VirtualHost *:443>
    DocumentRoot "/var/www/html"
    ServerName "ribosome.info"
    ServerAlias "www.ribosome.info"



<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>


Include /etc/letsencrypt/options-ssl-apache.conf

SSLCertificateFile /etc/letsencrypt/live/ribosome.info-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ribosome.info-0001/privkey.pem
</VirtualHost>
</IfModule>

和 django 的配置(django-le.conf):

<IfModule mod_ssl.c>
<VirtualHost *:8000>

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin,X-Requested-With,Content-Type,Accept"
Header set Access-Control-Allow-Methods "GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD"


ServerAdmin rtkushner@gmail.com
ServerName ribosome.info
ServerAlias www.ribosome.info

DocumentRoot /var/www/backend/

ErrorLog /home/ec2-user/httplogs/error.log
CustomLog /home/ec2-user/httplogs/access.log combined


Alias /static /var/www/backend/static
<Directory /var/www/backend/static>
    Require all granted
</Directory>


Alias /media /var/www/backend/media
<Directory /var/www/backend/media>
    Require all granted
</Directory>

<Directory /var/www/backend/rxz_backend>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>


WsgiScriptAlias / /var/www/backend/rxz_backend/wsgi.py process-group=ribosomeapi
WsgiDaemonProcess ribosomeapi python-path=/var/www/backend python-home=/var/www/venv
WsgiProcessGroup ribosomeapi

Include /etc/letsencrypt/options-ssl-apache.conf

SSLCertificateFile /etc/letsencrypt/live/ribosome.info/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ribosome.info/privkey.pem
</VirtualHost>
</IfModule>

这里是 django 的 settings.py 文件(位于 /var/www/backend/rxz_backend/settings.py):

import os,sys
import json
from dotenv import load_dotenv
load_dotenv(dotenv_path='/var/www/backend/rxz_backend/.env')
SECRET_KEY = os.getenv('SECRET_KEY')
DEBUG      = True

from pathlib import Path

BASE_DIR               =  Path(__file__).resolve().parent.parent

ALLOWED_HOSTS          =  ["*","ribosome.info","www.ribosome.info","50.18.117.38","ec2-50-18-117-38.us-west-1.compute.amazonaws.com","50.18.117.38"
        ]
CORS_ORIGIN_ALLOW_ALL  =  True

INSTALLED_APPS = [
    'corsheaders','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','rest_framework',#'neo4j_connector','static_files'
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware','django.middleware.common.CommonMiddleware','django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',]

ROOT_URLconf = 'rxz_backend.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates','Dirs': [],'APP_Dirs': True,'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},]

Wsgi_APPLICATION = 'rxz_backend.wsgi.application'


DATABASES = {
}
AUTH_PASSWORD_VALIDATORS = [
]


LANGUAGE_CODE  =  'en-us'
TIME_ZONE      =  'UTC'
USE_I18N       =  True
USE_L10N       =  True
USE_TZ         =  True


STATIC_ROOT  =  os.path.join(BASE_DIR,'static')
STATIC_URL   =  '/static/'


如果有人能向我指出错误或建议其他地方查看...,我将不胜感激!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?