我正在尝试使用 nginx 代理传递给两个 docker 容器。这是我的上游 conf 文件:
upstream api_servers {
server http://192.168.49.4:49155;
server http://192.168.49.4:49156;
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试加载它的内容:
nginx: [emerg] invalid host in upstream "http://192.168.49.4:49155" in /etc/nginx/conf.d/api_upstream.conf:3
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)
一旦我删除了 http:// 前缀,错误就会停止发生。这是为什么?
我正在尝试将 CloudFlare 提供的灵活 SSL 实施到我的站点。
这是我的 nginx 配置:
# PHP-FPM upstream; change it accordingly to your local config!
upstream php-fpm {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
## Listen ports
listen 443;
# use _ if you want to accept everything, or replace _ with domain
server_name example.com www.example.com;
location / {
#proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X_FORWARDED_PROTO https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Url-Scheme $scheme;
proxy_redirect off;
proxy_max_temp_file_size …
Run Code Online (Sandbox Code Playgroud) 我正在尝试重写针对我的站点的域 url,以便将所有域名重写为 www.example.com 并具有以下配置:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name _;
rewrite ^ $scheme://www.example.com$request_uri permanent;
location / {
# Allow for large file uploads
client_max_body_size 0;
proxy_http_version 1.1;
proxy_pass http://mysite;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
Run Code Online (Sandbox Code Playgroud)
server {
listen 80;
root /opt/site2/www;
index index.html index.htm;
# Redirecto root requests to Share
rewrite ^/$ /share;
location / {
# First attempt to serve request …
Run Code Online (Sandbox Code Playgroud) 我们有 QA 版本、UAT 版本和 webapp 的 DEV 版本。用户需要通过访问这些http://uat.company.com:41002/webapp
,http://qa.company.com:41002/webapp
和http://dev.company.com:41002/webapp
。在端口 41001 和端口 8080 上还有一个不同的 webapp,它们需要访问。
这些 url 必须在公司外部可用,而且我们只有一个可以访问它们的公共 IP 地址。因此,DNS 记录需要所有 3 个地址指向一个 IP。在那个单一的 IP 地址上,有一台服务器运行着 nginx。在后台,我需要每个 url 指向不同的服务器
http://uat.company.com --> 123.123.123.1
http://qa.company.com --> 123.123.123.2
http://dev.company.com --> 123.123.123.3
Run Code Online (Sandbox Code Playgroud)
恐怕我不知道正确的术语,但是 URI 的其余部分和端口也必须转移到 IP 地址。即如果有人访问
http://uat.company.com:41002/webapp/somepage`
Run Code Online (Sandbox Code Playgroud)
看起来好像那是他们访问过的页面,但实际上他们会查看
http://123.123.123.1:41002/webapp/somepage
Run Code Online (Sandbox Code Playgroud)
或者如果他们访问过
http://qa.company.com:8080/static/home.html
Run Code Online (Sandbox Code Playgroud)
他们真的会看
http://123.123.123.2:8080/static/home.html
Run Code Online (Sandbox Code Playgroud)
但他们的浏览器仍然会说 http://qa.company.com:8080/static/home.html
我试过了
server {
server_name uat.company.com;
listen 41001;
listen 41002;
listen 8080;
location / {
proxy_pass http://123.123.123.1:$server_port$uri;
proxy_set_header Host $host;
}
Run Code Online (Sandbox Code Playgroud)
}
但是,这给了我一个带有日志的错误网关 502 页面: …
我相信我的 nginx 配置之一有错误。我努力了:
$ sudo service nginx restart
* Restarting nginx nginx [fail]
$
Run Code Online (Sandbox Code Playgroud)
经过一番谷歌搜索后,我尝试了以下操作:
$ sudo service nginx -t
Usage: nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}
Run Code Online (Sandbox Code Playgroud)
但它只显示命令列表。nginx 日志或系统日志中没有有关配置错误的消息。我如何获得更详细的错误消息?
nginx ×5
rewrite ×2
301-redirect ×1
centos ×1
cloudflare ×1
proxy ×1
proxypass ×1
redirect ×1
vagrant ×1