我正在尝试配置default.conf以/etc/nginx/conf.d显示位于 的简单登录页面/home/ubuntu/project-source/company/entry/index.html。
据我所知,域已正确设置以指向服务器
A: test24.company.io -> <aws-elastic-IP>
Run Code Online (Sandbox Code Playgroud)
默认.conf:
server {
listen 80;
server_name localhost;
index index.html;
location / {
root /home/ubuntu/project-source/company/entry;
}
}
server {
server_name test24.company.io www.test24.company.io;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/test24.company.io/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test24.company.io/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 = test24.company.io) {
return 301 https://$host$request_uri;
} # managed by …Run Code Online (Sandbox Code Playgroud) 如果上游启动(max-age 1)绕过缓存并在关闭时使用缓存(proxy_cache_use_stale),我创建了以下配置:
proxy_cache_path /app/cache/ui levels=1:2 keys_zone=ui:10m max_size=1g inactive=30d;
server {
...
location /app/ui/config.json {
proxy_cache ui;
proxy_cache_valid 1d;
proxy_ignore_headers Expires;
proxy_hide_header Expires;
proxy_hide_header Cache-Control;
add_header Cache-Control "max-age=1, public";
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Cache-Date $upstream_http_date;
proxy_pass http://app/config.json;
}
}
Run Code Online (Sandbox Code Playgroud)
但是当上游关闭并且客户端仅获得 504 Gateway Timeout 时不使用缓存。我已经阅读了以下文章:
https://nginx.org/ru/docs/http/ngx_http_proxy_module.html#proxy_cache_use_stale
如何配置 NginX 仅在后端关闭时才提供缓存内容(5xx 响应代码)?
https://serverfault.com/questions/752838/nginx-use-proxy-cache-if-backend-is-down
它不像我期望的那样工作。任何帮助表示赞赏。
caching nginx nginx-location nginx-reverse-proxy nginx-config
默认情况下,我的nginx服务器将日志绘制到stdout和stderr。
我想将日志转发到我的系统日志服务器,并且我已经成功做到了,来自nginx.conf:
server {
...
error_log syslog:server=localhost:5447,facility=local7,tag=nginx_client,severity=error;
access_log syslog:server=localhost:5447,facility=local7,tag=nginx_client,severity=info;
...
}
Run Code Online (Sandbox Code Playgroud)
如何配置我的服务器以将日志绘制到stdout和stderr?
在我的 Nginx 配置中,我有这样的重定向规则:
map $uri $target {
'/test123' 'https://www.somedomain.com/test456';
}
map $uri $target_code {
'/test123' 301;
}
server {
listen 80 default;
if ($target_code = 301) {
return 301 $target;
}
if ($target_code = 302) {
return 302 $target;
}
}
Run Code Online (Sandbox Code Playgroud)
而且效果很好。但对于“如果”的看法是邪恶的
我想做出这样的声明:
server {
listen 80 default;
return $target_code $target;
}
Run Code Online (Sandbox Code Playgroud)
但在重新启动期间,Nginx 返回错误nginx: [emerg] invalid return code "$target_code" in /etc/nginx/nginx.conf
是否有可能以这种方式使用变量?或者也许有其他方法可以在没有任何 if 语句的情况下实现它?
我正在 Ubuntu 18.04 服务器上发布一个用 Python Pyramid 制作的网站。该网站是在HTTP运行正常,现在我想让它运行HTTPS按照这篇文章,但要安装我得到这个消息时:
IMPORTANT NOTES:
- Unable to install the certificate
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/dev.anything.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/dev.anything.com/privkey.pem
Your cert will expire on 2019-03-17. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
Run Code Online (Sandbox Code Playgroud)
这是我的配置文件,它位于/etc/nginx/sites-available/snow_service.nginx:
server {
listen 80; …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我们的域下的子文件夹中设置多个 WordPress 站点(即不是多站点),但我在配置 REST API 端点时遇到困难。例如,这个端点工作正常:
https://example.com/site1/?rest_route=/wp/v2/posts
Run Code Online (Sandbox Code Playgroud)
但是这个端点给出了 404:
https://example.com/site1/wp-json/wp/v2/posts
Run Code Online (Sandbox Code Playgroud)
我尝试在 nginx 配置中使用以下规则将失败的 url 重写为工作 url:
location /site1/wp-json {
rewrite ^/site1/wp-json(.*)$ /site1/?rest_route=$1;
}
location /site1/ {
try_files $uri $uri/ /site1/index.php$is_args$args;
}
Run Code Online (Sandbox Code Playgroud)
我在WordPress 文档或nginx wiki中看不到对 wp-json 的任何特殊处理。我在这里缺少什么?该网站的永久链接设置为Numeric( https://example.com/site1/archives/123如果这可能起作用,
编辑后的完整配置文件的要点和配置语法 lints 正常:
nginx -c /etc/nginx/nginx.conf -t
Run Code Online (Sandbox Code Playgroud)
nginx:配置文件/etc/nginx/nginx.conf语法正确
nginx:配置文件/etc/nginx/nginx.conf测试成功
我的 Nginx 配置由许多嵌套的 nginx 配置文件组成。有没有一种方法/命令可以帮助我查看最终/扩展的指令列表。
请在标记为重复之前阅读完整的问题,因为它不是重复的问题。我有一个 VPS,我想在其上部署多个 Web 应用程序(我已经阅读了相关帖子,当我们直接拥有子容器时,它们是完美的)。我的问题是不同的。我想管理每个具有自己的 nginx 的 Web 应用程序以路由到它的子域以及一些与它们相关的静态网站。我有两个码头工人。我的网络如下所示。图片。
我的 NGINX 反向代理应该负责将域路由到相应的 nginx 容器。我不确定是否可能(这就是我寻求帮助的原因)。如果有人可以提供更好的理解,我愿意接受建议。以下是我对 nginx 代理容器和其他 Web 应用程序 docker yaml 文件代码的配置。我用过NGINX 代理
NGINX 代理 Docker 撰写文件
version: "3.7"
services:
nginx-proxy:
image: jwilder/nginx-proxy:alpine
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
default:
external:
name: nginx-proxy
Run Code Online (Sandbox Code Playgroud)
网络应用 1 docker-compose.yml
version: "3.7"
networks:
default:
external:
name: nginx-proxy
yoda-network:
driver: bridge
services:
adminer:
container_name: ${APP_NAME}_adminer
image: adminer
depends_on:
- mysql
expose:
- 8080
environment:
VIRTUAL_HOST: yodaledger.com
VIRTUAL_PORT: 8080
networks:
- yoda-network …Run Code Online (Sandbox Code Playgroud) nginx docker jwilder-nginx-proxy nginx-reverse-proxy nginx-config
我已经为应用程序设置了入口,但想将我的 IP 地址列入白名单。所以我创建了这个 Ingress:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
cert-manager.io/cluster-issuer: letsencrypt
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/whitelist-source-range: ${MY_IP}/32
name: ${INGRESS_NAME}
spec:
rules:
- host: ${DNS_NAME}
http:
paths:
- backend:
serviceName: ${SVC_NAME}
servicePort: ${SVC_PORT}
tls:
- hosts:
- ${DNS_NAME}
secretName: tls-secret
Run Code Online (Sandbox Code Playgroud)
但是当我尝试访问它时,我收到 403 禁止,并且在 nginx 日志记录中我看到一个客户端 ip,但它来自集群节点之一,而不是我的家庭 ip。
我还使用此配置创建了一个 configmap:
data:
use-forwarded-headers: "true"
Run Code Online (Sandbox Code Playgroud)
在容器中的 nginx.conf 中,我可以看到已正确传递/配置,但我仍然收到 403 forbidden,仍然只有来自集群节点的客户端 IP。
我在 AKS 集群上运行,并且 nginx 入口控制器位于 Azure 负载均衡器后面。nginx 入口控制器 svc 公开为负载均衡器类型,并锁定由 svc 打开的节点端口。
我需要在 Nginx 中配置其他东西吗?
nginx kubernetes kubernetes-ingress nginx-config nginx-ingress
我正在尝试设置一个包含多个容器的 Web 服务器 - 但从我的反向代理的简单设置开始。
我的 docker-compose.yml如下所示:
version: '3'
services:
reverse-proxy:
container_name: reverse-proxy
hostname: reverse-proxy
image: nginx:latest
ports:
- 80:80
volumes:
- ./nginx-config/conf.d:/etc/nginx/conf.d
- ./html:/usr/share/nginx/html
environment:
- NGINX_PORT=80
- ENV=development
Run Code Online (Sandbox Code Playgroud)
具有nginx-config文件夹结构,如:
nginx-config
|- templates
|-default.conf.template
|- sites-available
|- mysite.conf.template
Run Code Online (Sandbox Code Playgroud)
和default.conf.template看起来像:
server {
listen ${NGINX_PORT} default_server;
listen [::]:${NGINX_PORT} default_server;
server_name _;
root /usr/share/nginx/html;
charset UTF-8;
error_page 404 /notfound.html;
location = /notfound.html {
allow all;
}
location / {
return 404;
}
access_log off;
log_not_found off; …Run Code Online (Sandbox Code Playgroud) nginx-config ×10
nginx ×9
docker ×2
caching ×1
certbot ×1
dns ×1
kubernetes ×1
lets-encrypt ×1
ssl ×1
stderr ×1
stdout ×1
wordpress ×1