AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-401483

bwright's questions

Martin Hope
bwright
Asked: 2022-11-26 02:14:06 +0800 CST

从在 docker 容器中运行的 django 应用程序连接到主机 postgresql

  • 5

我正在尝试从在 docker 容器中运行的 django 应用程序连接到我的主机 postgresql 服务器(版本 14)。

这是我的设置

docker-compose.yml:

version: '3'
services: 
   web:
     build: .
       container_name: dm-api
     volumes: 
       - .:/code
       - static:/code/dojo_manager/static
       - media:/code/dojo_manager/media
     expose: 
       - 8080
     extra_hosts:
       - "database:172.17.0.1"
     command: bash -c "systemctl restart cron && python manage.py collectstatic --no input && python manage.py migrate && gunicorn --workers=3 dojo_manager.wsgi -b 0.0.0.0:8080"
   nginx:
     restart: always
     build: ./nginx/
     volumes: 
        - ./nginx/:/etc/nginx/conf.d
        - ./logs/:/code/logs
        - static:/code/static
        - media:/code/media
     ports: 
        - "1221:80"
     links:
        - web  
 volumes: 
   media:
   static:  

pg_hba.conf:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             172.17.0.0/16           md5
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer

配置:

 docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
    inet6 fe80::42:41ff:fe7c:b9e9  prefixlen 64  scopeid 0x20<link>
    ether 02:42:41:7c:b9:e9  txqueuelen 0  (Ethernet)
    RX packets 40651  bytes 6850716 (6.8 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 51087  bytes 570351402 (570.3 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

postgresql.conf:

listen_addresses = '*'

但是当我启动容器时出现错误:

django.db.utils.OperationalError: connection to server at "database" (172.17.0.1), port 5432 failed: FATAL:  no pg_hba.conf entry for host "172.19.0.2", user "dtuser", database "dtdb", SSL encryption
connection to server at "database" (172.17.0.1), port 5432 failed: FATAL:  no pg_hba.conf entry for host "172.19.0.2", user "dtuser", database "dtdb", no encryption

我尝试了各种在线资源和文档。但是,我似乎无法运行连接。

非常感谢任何提示/帮助。最佳班尼迪克特

docker
  • 1 个回答
  • 29 Views
Martin Hope
bwright
Asked: 2017-02-22 04:46:00 +0800 CST

使用 AJP 时会话无效

  • 1

我有以下设置: Apache 运行前端(AngularJS)
Tomcat 7 运行后端(Spring MVC,Spring Security)

阿帕奇配置

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

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

    LoadModule proxy_module libexec/apache2/mod_proxy.so
    LoadModule proxy_ajp_module libexec/apache2/mod_proxy_ajp.so

    ProxyRequests     off
    ProxyPreserveHost on

    ProxyPass         /api/  ajp://132.230.166.21:8009/OntoRais/api/
    ProxyPassReverse  /api/  ajp://132.230.166.21:8009/OntoRais/api/

    Alias /rais "/home/bwright/Repositories/ontology-toolchain/WebClient"
    <Directory "/home/bwright/Repositories/ontology-toolchain/WebClient">
        Order allow,deny
        Allow from all
        Require all granted
    </Directory
</VirtualHost>

可以看到,我使用 ajp 协议将所有 api 调用传递给 tomcat 服务器。

Tomcat 配置 (Server.xml)

干净安装没有任何变化,除了:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"  enableLookups="false"/>

现在,当我尝试通过前端访问 tomcat 资源时,我得到 403

HTTP Status 403 - Full authentication is required to access this resource accessing /OntoRais/api/user

在我得到的tomcat服务器日志中

13:25:10.034 [ajp-bio-8009-exec-7] DEBUG o.s.s.w.s.SessionManagementFilter - Requested session ID ED0779DC647DEE3C58DEA7059C260594 is invalid. 

当通过 bowser 直接访问 tomcat 服务器的相同资源时, http://localhost:8080/OntoRais/api/user一切正常。

编辑

澄清一下,132.230.166.21 与 localhost 是同一台机器。我将配置更改为 localhost ,没有任何更改。

希望这里有人可以帮助我谢谢本尼迪克特

tomcat mod-proxy-ajp apache-2.4
  • 1 个回答
  • 474 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve