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-578430

Mervin Hemaraju's questions

Martin Hope
Mervin Hemaraju
Asked: 2024-03-31 04:17:38 +0800 CST

使用带有 CertBot 证书和域名的 Flask 应用程序对两台服务器进行负载平衡

  • 5

我有两台服务器,我们称它们为ServerA和ServerB。

我在 NameCheap 上购买了一个域名,我们称之为它example.com

每台服务器都有在不同端口上运行的 docker 容器(Flask Web 应用程序)。

例子:

WebApp1 running on port 8080
WebApp2 running on port 8081
.
.

两台服务器的配置相同。

然后,我在端口 443 上使用 nginx 作为反向代理,每个端口都有自己的子域。

例子:

WebApp1 running on port 8080 will be accessible via test1.example.com
WebApp2 running on port 8081 will be accessible via test2.example.com
.
.

我正在使用 CertBot 来获取 SSL 证书。

我的两台服务器托管在 OCI(Oracle 云)上,我在 OCI 上构建了一个网络负载均衡器来平衡服务器之间的流量。

以下是我的配置:

nginx.conf

user nginx;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 800;
}

http {

    ##
    # Basic Settings
    ##
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # General Logging Settings
    ##
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##
    # gzip on;
    # gzip_vary on;
    # gzip_min_length 10240;
    # gzip_proxied expired no-cache no-store private auth;
    # gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
    # gzip_disable "MSIE [1-6]\.";

    ##
    # Web Apps configurations
    ##
    include /etc/nginx/sites-enabled/*;
}

/etc/nginx/sites-enabled/test1.example.com

server {
  server_name   test1.example.com;

  location / {
    access_log  /var/log/nginx/test1/access.log;
    error_log  /var/log/nginx/test1/error.log;
    proxy_pass  http://localhost:8080;
  }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/test1.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/test1.example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = test1.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

  server_name   test1.example.com;
    listen 80;
    return 404; # managed by Certbot
}

目前,域名 test1.example.com 有一条到 ServerA 的 A 记录,该记录工作正常,我可以访问我的 WebApp。

但我希望域指向我的负载均衡器,以便我可以平衡两台服务器上的流量。但我不能这样做,除非我在两台服务器上颁发 SSL 证书,但我不能。因为在 上发布 test1.example.com 后ServerA,这样做ServerB会导致 certbot 出错,指出证书已分配给ServerA。

有人可以帮助我如何做到这一点吗?

nginx
  • 1 个回答
  • 118 Views
Martin Hope
Mervin Hemaraju
Asked: 2023-05-26 14:37:20 +0800 CST

域用户目录被创建为 /home/username@domain 而不是 /home/username

  • 4

我正在使用 amazon linux 2023 盒子,我使用realmd.

问题是,当我尝试使用我的 AD 凭据登录时,用户目录被创建为而/home/username@domain不是/home/username.

这是我的/etc/sssd/sssd.conf文件:

[sssd]
domains = avengers.local
config_file_version = 2
services = nss, pam
default_domain_suffix = AVENGERS.local

[domain/avengers.local]
default_shell = /bin/bash
krb5_store_password_if_offline = True
cache_credentials = True
krb5_realm = AVENGERS.LOCAL
realmd_tags = manages-system joined-with-adcli
id_provider = ad
fallback_homedir = /home/%u@%d
ad_domain = avengers.local
ldap_id_mapping = True
access_provider = ad
ad_gpo_access_control = disabled

有人可以帮帮我吗 ?

linux
  • 1 个回答
  • 17 Views
Martin Hope
Mervin Hemaraju
Asked: 2021-12-21 07:07:26 +0800 CST

Bash 脚本中的环境变量为空

  • 1

我有一个在 AWS 上部署的 EC2 实例。

我正在使用 Amazon Linux 2,并且我正在将用户数据传递给它:

userdata_file.write(
        f'''
        #!/bin/bash\n
        export PAGERDUTYAPIKEY='mykey'\n
        sudo yum install git -y\n
        chmod +x ./basic_test.sh \n
        echo $PAGERDUTYAPIKEY> /home/ec2-user/pagerdutyapikey1.txt\n
        sudo ./basic_test.sh
        '''.strip()
    )

basic_test.sh

#!/bin/bash

echo "s/enterpagerdutyapikey/${PAGERDUTYAPIKEY}/g" > path.txt

但是,当我运行它时,path.txt它会像这样回显:

s/enterpagerdutyapikey//g

但是当我在服务器中 ssh 并运行相同的 bash 脚本时,它会这样回显:

s/enterpagerdutyapikey/mykey/g

知道为什么$PAGERDUTYAPIKEY当我运行用户数据时环境变量呈现为空吗?

linux bash amazon-web-services amazon-linux-2
  • 1 个回答
  • 607 Views
Martin Hope
Mervin Hemaraju
Asked: 2021-04-10 03:30:55 +0800 CST

使用 PGP 公钥生成指纹

  • 1

我有一个 PGP 公钥,我需要获取它的指纹。

我的公钥是这样的:

-----BEGIN PGP PUBLIC KEY BLOCK-----
mQlDBF4w............................
.
.
.
=uYgH
-----END PGP PUBLIC KEY BLOCK-----

我尝试使用该命令gpg --with-fingerprint key.txt,但它给了我以下输出并且其中没有指纹:

gpg: WARNING: no command supplied.  Trying to guess what you mean ...
pub   rsa4096 2020-01-28 [SC]
uid           cko_key <[email protected]>
sub   rsa4096 2020-01-28 [E]

有人可以帮帮我吗?

pgp fingerprint openpgp
  • 2 个回答
  • 3669 Views
Martin Hope
Mervin Hemaraju
Asked: 2020-12-06 14:19:13 +0800 CST

Python 在导出环境变量时抛出 KeyError

  • 0

我有一个奇怪的情况,我有一个 secret.env 文件,我在其中设置了所有环境变量:

秘密.env

export TWITTER_CONSUMER_KEY="something"
export TWITTER_CONSUMER_SECRET="something"

然后我构建了一个 docker 文件来导出所有变量并像这样运行应用程序:

FROM python:3.8-slim-buster

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Install the dependencies
RUN pip install -r requirements.txt

RUN find . -name \*.pyc -delete

# Export all variables
RUN /bin/bash -c "source secret.env";

# tell the port number the container should expose
EXPOSE 8083

# run the command
ENTRYPOINT ["python", "run.py"]

但是,这引发了一个关键错误:

$ docker run --name fortweet --rm -i -t fortweet:latest bash
Traceback (most recent call last):
  File "run.py", line 1, in <module>
    from app import socketio, app
  File "/app/app/__init__.py", line 65, in <module>
    app = create_app()
  File "/app/app/__init__.py", line 38, in create_app
    my_settings = settings.TwitterSettings.get_instance()
  File "/app/app/setup/settings.py", line 47, in get_instance
    TwitterSettings()
  File "/app/app/setup/settings.py", line 14, in __init__
    self.consumer_key = os.environ["TWITTER_CONSUMER_KEY"]
  File "/usr/local/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'TWITTER_CONSUMER_KEY'

当我在我的 Windows 上运行它时,它工作正常!

有人可以帮我吗?

ubuntu environment-variables python docker-machine
  • 1 个回答
  • 1348 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