【发布时间】:2018-07-30 00:17:18
【问题描述】:
我在将我的 wordpress Pod 连接到公开的 nginx 代理 pod 时遇到问题。我遇到的主要问题是:*1 connect() failed (111: Connection refused) while connecting to upstream
我的 docker 容器设置为模仿 LAMP 堆栈,暴露端口 80,在容器内我的 apache conf 如下所示:
<VirtualHost *:80>
DocumentRoot /var/www/html
ErrorLog /var/log/error.log
CustomLog /var/log/acces.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
在 pod 部署中,我也将容器端口设置为 80,这是 Kubernetes 部署中暴露该端口的部分
ports:
- containerPort: 80
name: http
在 pod 的服务上,我让它选择部署 pod
apiVersion: v1
kind: Service
metadata:
name: project-legacy-wp
labels:
app: project
role: legacy-wp
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: project
role: legacy-wp
最后我的 nginx 代理看起来像这样,这就是我有点不稳定的地方。我不熟悉 nginx 代理,我没有设置它。我尽力让它与集群中的其他站点相似
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'CIPHERS';
ssl_prefer_server_ciphers on;
ssl_certificate path/to/certs;
ssl_certificate_key path/to/certs;
server_name example.com;
client_max_body_size 4G;
keepalive_timeout 10;
location / {
access_log on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://project-legacy-wp;
}
}
【问题讨论】:
标签: apache docker nginx proxy kubernetes