gpt4 book ai didi

nginx - Passenger + Nginx + Docker应用程序设置

转载 作者:行者123 更新时间:2023-12-02 18:40:21 26 4
gpt4 key购买 nike

TL; DR =无法让Passenger / Nginx从Django调用我们的应用程序。 “passenger-status”未显示当前运行的非Docker服务器中显示的正确应用程序组。

尝试将运行中且正在运行的Passenger + Nginx + Django系统转换为Docker镜像。我们从基本的Phusion:passenger-docker镜像开始,现在尝试使其像我们的实时系统一样运行。我们遵循了[here]指南,但是在运行容器时,Passenger和Nginx不会运行我们的应用程序。乘客提供以下输出:

root@e8da5a56faec:/# passenger-status
Using /usr/local/rvm/gems/ruby-2.0.0-p648
Version : 5.1.2
Date    : 2017-04-25 01:59:00 +0000
Instance: wXh9AKCm (nginx/1.10.2 Phusion_Passenger/5.1.2)

----------- General information -----------
Max pool size : 6
App groups    : 0
Processes     : 0
Requests in top-level queue : 0

----------- Application groups -----------
root@e8da5a56faec:/#

-
root@e8da5a56faec:/# passenger-memory-stats
Using /usr/local/rvm/gems/ruby-2.0.0-p648
Version: 5.1.2
Date   : 2017-04-25 01:59:49 +0000
------------- Apache processes -------------
*** WARNING: The Apache executable cannot be found.
Please set the APXS2 environment variable to your 'apxs2' executable's filename, or set the HTTPD environment variable to your 'httpd' or 'apache2' executable's filename.


--------- Nginx processes ----------
PID   PPID  VMSize    Private  Name
------------------------------------
46    1     228.4 MB  0.7 MB   nginx: master process /usr/sbin/nginx
49    46    228.4 MB  ?        nginx: worker process
1858  9     228.4 MB  3.5 MB   /usr/sbin/nginx
### Processes: 3
### Total private dirty RSS: 4.13 MB (?)


---- Passenger processes ----
PID  VMSize    Private  Name
-----------------------------
26   441.1 MB  1.2 MB   Passenger watchdog
29   654.1 MB  2.9 MB   Passenger core
35   449.3 MB  ?        Passenger ust-router
### Processes: 3
### Total private dirty RSS: 4.13 MB (?)

Nginx.conf(如下)
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user app;
#user nobody;
worker_processes 1;

error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;

pid /run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
include /etc/nginx/passenger.conf;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;

keepalive_timeout 65;


index index.html index.htm;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server_tokens off;
server {
listen 80 default_server;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name yourserver.com;
root /home/app/public/;
passenger_enabled on;
passenger_python /usr/bin/python3.5;
ssl_certificate /etc/letsencrypt/live/yourserver.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/yourserver.com/privkey.pem; # managed by Certbot

ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
add_header X-Frame-Options SAMEORIGIN;

location /static {
alias /home/app/src_django/assets;
}

}
}

Dockerfile(下)
FROM phusion/passenger-full

ENV NGINX_DIR=/etc/nginx
ENV APP=/home/app/webapp
ENV SCH_DIR=/your-scheduling

COPY ./nginx/nginx.conf $NGINX_DIR/

EXPOSE 80
EXPOSE 443

# Make SSL Cert directory
RUN mkdir -p /etc/letsencrypt/live/yourserver.com

# SSL Certs
COPY ./nginx/*.pem /etc/letsencrypt/live/yourserver.com/

# Random Passenger Stuff
ADD ./nginx/env.conf /etc/nginx/main.d/
ADD ./nginx/secret_key.conf /etc/nginx/main.d/
ADD ./nginx/gzip_max.conf /etc/nginx/conf.d/


# Get Code
COPY ./web $APP
COPY ./your-scheduling $SCH_DIR

# Install MySQL deps
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install -y libmysqlclient-dev

# Install Pip
RUN apt install -y python3-pip

# Run
RUN pip3 install -r $APP/requirements.txt
RUN python3.5 $APP/manage.py collectstatic --noinput
RUN cd /your-scheduling && python3.5 /your-scheduling/setup.py install && cd -

# Things because Passenger says so
RUN rm -f /etc/service/nginx/down
RUN rm -f /etc/nginx/sites-enabled/default
ADD ./nginx/webapp.conf /etc/nginx/sites-enabled/webapp.conf
# RUN mkdir /home/app/webapp

docker-compose.yml
app:
  restart: always
  build: ./
  links:
   - mysql:mysql
  environment:
   YOUR_KEY_FILE: /home/app/webapp/src_django/keyfile.txt
   DJANGO_SETTINGS_FILE: src_django.settings.settings
   YOUR_PROD: "True"
   PYTHONPATH: /home/app/webapp

mysql:
  restart: always
  image: mariadb:latest
  ports:
   - "3306"
  environment:
   MYSQL_ROOT_PASSWORD: password
   MYSQL_DATABASE: mydb
   MYSQL_USER: db_user
   MYSQL_PASSWORD: password

最佳答案

嗯...尝试添加:

ports:
- 80:80

app服务。

关于nginx - Passenger + Nginx + Docker应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43600562/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com