我正在尝试配置nginx作为我自己在ubuntu上托管的网站的反向代理。没有server_name,因为我正在使用虚拟机IP。
我想要的是,如果我把IP放在浏览器上,然后网站显示,如果我把IP:5984, couchdb信息显示
我已经尝试了多种选择,这完全适用于。net核心网站,但无法访问couchdb
这是我的配置
server {
listen 80;
location /{
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://localhost:5984/;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
我也试过这个:
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 5984;
location /{
proxy_pass http://localhost:5984/;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
谢谢!
根据你刚才共享的配置,看起来NGINX和你的couchdb节点运行在同一个实例上(单节点?)你不能在nginx和couchdb上使用相同的端口5984
!这在Ubuntu上不起作用。如果你想让反向代理监听5984
,让couchbd监听其他东西,例如49152
。
如果couchdb和nginx使用相同的端口,error.log的grep
2021/02/09 14:25:15 [emerg] 78949#78949: bind() to 0.0.0.0:5984 failed (98: Address already in use)
2021/02/09 14:25:15 [notice] 78949#78949: try again to bind() after 500ms
2021/02/09 14:25:15 [emerg] 78949#78949: bind() to 0.0.0.0:5984 failed (98: Address already in use)
2021/02/09 14:25:15 [notice] 78949#78949: try again to bind() after 500ms
2021/02/09 14:25:15 [emerg] 78949#78949: bind() to 0.0.0.0:5984 failed (98: Address already in use)
2021/02/09 14:25:15 [notice] 78949#78949: try again to bind() after 500ms
2021/02/09 14:25:15 [emerg] 78949#78949: bind() to 0.0.0.0:5984 failed (98: Address already in use)
2021/02/09 14:25:15 [notice] 78949#78949: try again to bind() after 500ms
2021/02/09 14:25:15 [emerg] 78949#78949: bind() to 0.0.0.0:5984 failed (98: Address already in use)
2021/02/09 14:25:15 [notice] 78949#78949: try again to bind() after 500ms
2021/02/09 14:25:15 [emerg] 78949#78949: still could not bind()
我正在使用docker在我的testserver上运行couch db:
docker run -p 55984:5984 -d -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password couchdb
6339f2af29ed couchdb "tini -- /docker-ent…" 5 seconds ago Up 4 seconds 4369/tcp, 9100/tcp, 0.0.0.0:55984->5984/tcp elegant_archimedes
简单的curl直接响应couchdb:
$curl localhost:55984 | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 247 100 247 0 0 2440 0 --:--:-- --:--:-- --:--:-- 2470
{
"couchdb": "Welcome",
"version": "3.1.1",
"git_sha": "ce596c65d",
"uuid": "317efcb5527237d5c9e974c5d3680ae3",
"features": [
"access-ready",
"partitioned",
"pluggable-storage-engines",
"reshard",
"scheduler"
],
"vendor": {
"name": "The Apache Software Foundation"
}
}
这是我的工作NGINX配置
server {
listen 80;
# Proxy location to your backend application. Listen on Port 80.
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
}
}
server {
listen 5984;
# CouchDB ProxyLocation. Using InstanceIP with Port `5984`.
location / {
proxy_pass http://localhost:55984;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
测试:通过NGINX访问CouchDB
$curl localhost:5984 | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 247 100 247 0 0 8095 0 --:--:-- --:--:-- --:--:-- 8233
{
"couchdb": "Welcome",
"version": "3.1.1",
"git_sha": "ce596c65d",
"uuid": "875045f1b2314443a21236808b0223cf",
"features": [
"access-ready",
"partitioned",
"pluggable-storage-engines",
"reshard",
"scheduler"
],
"vendor": {
"name": "The Apache Software Foundation"
}
}
get out to Backend App using NGINX
$curl localhost
<h1>Wellcome! Please Login!</h1>
<form action="doLogin.php" method="post">
<input type="text" id="user" name="user" />
<input type="password" id="password" name="password" />
<input type="submit" value="Login">
</form>
所以在这个配置下它可以工作。目前使用NGINX 1.19.5在CentOS7没有SELinux!