gpt4 book ai didi

nginx - centos7 上设置的 certbot 和 nginx 子域

转载 作者:太空宇宙 更新时间:2023-11-03 17:23:15 24 4
gpt4 key购买 nike

我正在尝试使用 Let's Encrypt 的 certbot 提供的 ssl 加密在 Centos7 服务器上的 nginx 中设置一个具有一个子域(暂时)的网站。

我已经成功安装了 nginx,我已经设置了我的域:example.com www.example.comci.example.com 并且毫无问题地获得了颁发的证书(我的浏览器显示“安全”并且它自动从 http 请求重定向到 https。)

现在我想让 ci.example.com 代理到 localhost:6500 端口(proxy_pass 我相信它被调用了)。我试过以下: this blog post from 2014但是 nginx 继续提供标准的“欢迎来到 Nginx 页面”。

所有其他文章/教程都是针对旧版本的 nginx(不使用/etc/nginx/nginx.conf。

这里是/etc/nginx/nginx.conf

http {
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;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

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

# 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 {
server_name example.com www.example.com;

root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/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 = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


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

if ($host = ci.example.com) {
return 301 https://$host$request_uri;
} #added by me

listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 404; # managed by Certbot

最佳答案

我已经弄明白了,并为后代保存了它。

在运行 certbot --nginx 命令之前,我没有正确设置 nginx。

这是你应该做的:

来自全新安装的 Centos 7

通过 sudo yum update -y 确保 Centos 是最新的

然后通过以下方式安装nginx:sudo yum install nginx -y

它是默认设置,但这确保它是最新的。

然后关注this获得不安全的 http://ci.yoursite.comhttp://www.yoursite.com 的指南,按照您的意愿工作。

注意 - 如果您遇到无法启动 nginx 的问题,原因是: [emerg] open() "/usr/share/nginx/logs/ci.yoursite.access.日志”失败(13:权限被拒绝)

使用:su -c "setenforce 0" 它将 SELinux 设置为宽容模式并允许 nginx 启动。

然后跟随: This guide让 Let's Encrypt 和 Certbot --nginx 正常工作。

你的最终 /etc/nginx/conf.d/ci.yourserver.conf 在这个例子中应该看起来像这样重新路由到端口 6500:

server {

server_name ci.example.com;
access_log logs/ci.example.access.log main;

root /var/www/ci.example.com/html;
index index.html index.htm;

location / {
proxy_pass http://localhost:6500;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
proxy_buffers 4 32k;
client_max_body_size 8m;
client_body_buffer_size 128k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/ci.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ci.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 = ci.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;
listen [::]:80;

server_name ci.example.com;
return 404; # managed by Certbot


}

关于nginx - centos7 上设置的 certbot 和 nginx 子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52467952/

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