我正在尝试使用由Let's Encrypt的certbot提供的ssl加密,在Centos7服务器上的nginx中设置一个子域(暂时) .
我已经成功安装了nginx,我已经设置了我的域名: example.com
www.example.com
和 ci.example.com
并且没有任何问题获得了颁发的证书(我的浏览器说'secured'并且它自动从http请求重定向到https . )
现在我希望 ci.example.com
代理通过localhost:6500端口( proxy_pass
我相信它已经尝试过以下:this blog post from 2014但是nginx继续提供标准"Welcome to Nginx page" .
所有其他文章/教程都是针对旧版本的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
1 回答
我已经把它想出来并为后代保存了这个 .
在运行certbot --nginx命令之前,我没有正确设置nginx .
这是你应该做的:
From a clean install of Centos 7
通过
sudo yum update -y
确保Centos是最新的然后通过以下方式安装nginx:
sudo yum install nginx -y
它是默认的,但这确保它是最新的 .
然后按照this指南获取不安全的
http://ci.yoursite.com
和http://www.yoursite.com
按需使用 .Note - if you have issues with being unable to start nginx due to:
[emerg] open() "/usr/share/nginx/logs/ci.yoursite.access.log" failed (13: Permission denied)
使用:
su -c "setenforce 0"
它会将SELinux设置为许可模式并允许nginx启动 .然后按照:This guide让Let的加密和Certbot --nginx工作 .
在这个例子中,你的最终
/etc/nginx/conf.d/ci.yourserver.conf
应该像这样重新路由到端口6500: