标签: nginx

nginx 无法使用不同的根位置加载 wordpress 子文件夹

我们在不同路径的根域的子文件夹中安装了 wordpress,即使在该位置使用 root,wordpress 安装仍然加载域站点的根。

server {
  listen              80;
  server_name         domain.com;
  return              301 https://$server_name$request_uri;
}

server {
  listen              443 ssl;
  server_name         domain.com;

  ssl                 on;
  #ssl_certificate     /var/www/certs/star.domain.com.cert;
  #ssl_certificate_key /var/www/certs/star.domain.com.key;
  ssl_certificate      /var/www/certs/cert_chain.crt;
  ssl_certificate_key  /var/www/certs/__domain_com.key;
  ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;

  return              301 https://www.$server_name$request_uri;
}

server {
  ## Default Server Settings
  include             /etc/nginx/basic.conf;

  listen              443 ssl;
  server_name         www.domain.com;

  access_log          /var/log/nginx/domain.access.log;
  error_log           /var/log/nginx/domain.error.log;

  root                /var/www/domain/current;
  index               index.php index.html;

  ssl                 on;
  #ssl_certificate     /var/www/certs/star.domain.com.cert;
  #ssl_certificate_key /var/www/certs/star.domain.com.key;
  ssl_certificate      /var/www/certs/cert_chain.crt;
  ssl_certificate_key  /var/www/certs/__domain_com.key;
  ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers …
Run Code Online (Sandbox Code Playgroud)

nginx wordpress

1
推荐指数
1
解决办法
4272
查看次数

如何从 NGINX 获取 Gunicorn 的真实远程 IP

我总是将本地主机作为远程 IP。我的应用程序在 Nginx-Gunicorn 下运行

这是我对 nginx 的配置:

server { 
   listen      80; 
   server_name api.mydomain.com;

   charset     utf-8;

   client_max_body_size 1M; 

   location / { 
      set_real_ip_from 127.0.0.1/32;
      proxy_set_header X-Forwarded-Host $host:$server_port;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      proxy_pass http://aiohttp;
   }

   access_log /var/log/nginx/api_access.log;
   error_log  /var/log/nginx/api_error.log;
}
Run Code Online (Sandbox Code Playgroud)

这是我的 gunicorn 日志格式:

access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
Run Code Online (Sandbox Code Playgroud)

我的枪炮日志是这样的:

127.0.0.1 - - [28/Apr/2017:12:52:53 +0000] "GET /entrypoint?p=2&d=123456 HTTP/1.0" 200 379 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36"
Run Code Online (Sandbox Code Playgroud)

nginx gunicorn

1
推荐指数
1
解决办法
3611
查看次数

通过 systemd 管理自编译的 Nginx

我从源代码编译了 Nginx,现在我想通过 systemd 来管理它systemctl start,stop,restart,reload,enable nginx.service。我需要做什么才能启用它?

nginx systemd

1
推荐指数
1
解决办法
4193
查看次数

nginx反向代理多个位置

我想为多个应用程序制作一个反向代理。
像这样的东西:

https://proxyip/app1 -> https://10.10.0.1/
https://proxyip/app2 -> https://10.10.0.2/
etc.
Run Code Online (Sandbox Code Playgroud)

目前,我的配置是:

server {
    listen 443 ssl;
    server_name _;

    ssl_certificate     /etc/nginx/cert.crt;
    ssl_certificate_key /etc/nginx/cert.key;

    proxy_set_header    X-Real-IP               $remote_addr;
    proxy_set_header    Host                    $host;
    proxy_set_header    X-Forwarded-For         $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto       $scheme;

    client_max_body_size 0;

    error_log   syslog:server=unix:/dev/log;
    access_log  syslog:server=unix:/dev/log;

    location /app1/ {
        proxy_pass https://10.10.0.1/;
    }

    location /app2/ {
        proxy_pass https://10.10.0.2/;
    }

    location ~ /\. {
        deny all;
    }
}
Run Code Online (Sandbox Code Playgroud)

但没有任何作用。
当我转到https://proxyip/app1它时,它会将我重定向到https://proxyip/Account/login404。它应该转到https://proxyip/app1/Account/login. 这是日志:

Jun 06 15:05:44 my_proxy nginx[3829]: my_proxy nginx: 192.168.0.10 - - [06/Jun/2017:15:05:44 +0300] …
Run Code Online (Sandbox Code Playgroud)

nginx reverse-proxy

1
推荐指数
2
解决办法
2万
查看次数

如何配置 Nginx 以提供来自 CDN 的静态文件

我有一个 SPA ( ReactJSwith React-Router)index.html用作入口点。为了使前端路由器正常工作,我需要index.html为所有匹配的 URL 返回文件。

我试过使用但proxy_pass失败了(见下文),

server {
    listen 80;
    proxy_set_header Host $http_host;
    proxy_set_header x-forwarded-for $remote_addr;


    location /appname/(?<section>.*) {
        proxy_pass http://cdn.us-west-2.edge.aws/666/index.html;
    }
}
Run Code Online (Sandbox Code Playgroud)

我也准备好了,try_files但这似乎只适用于本地文件。

我想要达到的效果,

  1. 当用户访问 http://example.com/appname
  2. http://cdn.us-west-2.edge.aws/666/index.html应提供静态内容


  1. 当用户访问 http://example.com/appname/abc
  2. http://cdn.us-west-2.edge.aws/666/index.html应提供静态内容


  1. 当用户访问 http://example.com/appname/abc/def
  2. http://cdn.us-west-2.edge.aws/666/index.html应提供静态内容

nginx

1
推荐指数
1
解决办法
7669
查看次数

nginx 代理缓存不起作用

我代理到外部 JSON api 并尝试缓存代理响应。为了确定代理缓存是否正常工作,我添加了

add_header X-Cached $upstream_cache_status;
Run Code Online (Sandbox Code Playgroud)

并始终看到一个MISS值。

我的 nginx 配置位置:

location /api/tides {
  proxy_hide_header Cache-Control;
  proxy_ignore_headers Cache-Control;
  proxy_cache worldtidecache;
  proxy_set_header Host www.worldtides.info;
  proxy_pass https://example.com/api/$query_string;
  add_header X-Cached $upstream_cache_status;
}
Run Code Online (Sandbox Code Playgroud)

在此之前我已经proxy_cache_path设置

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=worldtidecache:100m max_size=1g inactive=48h use_temp_path=off;
Run Code Online (Sandbox Code Playgroud)

www-data 具有读/写访问权限 /var/cache/nginx

我假设proxy_buffering设置为,on因为我没有任何明确的设置。

nginx 配置有效。我已经测试过它nginx -c nginx.conf -t

??sudo nginx -c nginx.conf -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Run Code Online (Sandbox Code Playgroud)

我已经跟踪了error.logaccess.log …

nginx cache

1
推荐指数
1
解决办法
2947
查看次数

用于设置 nginx 反向代理的解析器指令

当使用 gunicorn 应用服务器(后端应用服务器和 nginx 之间典型的一对一映射)将 nginx 设置为反向代理时,我配置了以下内容:

upstream my_server {

  server unix:/home/user/folder/app/app.sock  fail_timeout=0;
}

location @https_proxy_to_app {
    proxy_set_header X-Forwarded-Proto https;
    include proxy_params;
    proxy_redirect off;
    proxy_pass http://my_server;
}
Run Code Online (Sandbox Code Playgroud)

许多关于该主题的文献都规定了这一点。虽然这有效,但我有几个问题。

首先(也是微不足道的),为什么需要包含http://proxy_pass http://my_server;

其次(更重要的是),我是否需要resolver为这种设置设置指令?我没有使用 AWS 的 Elastic Load Balancer,而且很多围绕该指令的处方 恰好都围绕着 AWS ELB。有人可以用外行的话解释为什么以及如何设置它吗?意外的服务器管理员在这里,所以需要专家的意见。resolver

请注意,我也在使用 OSCP 装订。

nginx

1
推荐指数
1
解决办法
8369
查看次数

双活应用服务器如何实现高可用?

我需要以这样一种方式设置我的应用程序,它使我的停机时间接近 0。我的一个数据中心在德克萨斯州,另一个在维加斯。现在,如果我在 TX 被认为是 PR 的服务器出现故障,所有流量都将转移到拉斯维加斯服务器,在我的情况下是 DR(灾难恢复)。

如果我们使用 HAProxy 或 NginX 等软件负载均衡器,使用 Keepalived(检查 DR 站点负载均衡器和 PR 站点负载均衡器之间的心跳),我们将最终设置主动-被动负载均衡以克服故障转移。在这里,我们的应用程序将处于 Active-Active 模式。

在此处输入图片说明

上图显示,所有传入流量都将到达负载均衡器的虚拟 IP(主动 PR 负载均衡器和被动 DR 负载均衡器,它们之间启用了心跳)。如果 PR 站点负载均衡器处于活动状态,那么它会将负载路由到 PR 站点 Portal 应用程序实例以及 DR 站点 Portal 实例(因为两个站点都处于活动状态),此时 DR 站点负载均衡器将处于空闲状态并不断监视其性能主动负载均衡器。如果 PR 站点出现故障,则 DR 站点将变为活动状态并自动指向 DR 站点 Portal 应用程序实例。

但我听说,使用 Keepalived 设置主动-被动负载平衡器的问题是,它在 LAN 中工作,但在 WAN 设置中无法工作。在我们的例子中,主动 PR 负载均衡器将在 TX,而被动 DR 负载均衡器将在维加斯。

那么,要通过故障转移设置实现 HA,我该如何使用软件负载平衡器?

domain-name-system nginx high-availability load-balancing haproxy

1
推荐指数
1
解决办法
1316
查看次数

Nginx 错误日志不会读取变量

在我的虚拟主机中,我有:

root   /var/www/$server_name/public_html;
index  index.php;

access_log /var/log/nginx/$server_name.access.log;
error_log  /var/log/nginx/$server_name.error.log debug;
Run Code Online (Sandbox Code Playgroud)

对于根和访问日志的$server_name工作。它不适用于错误日志。

在此处输入图片说明

我看到它是由 root 而不是 pi 设置的(我使用pi而不是data-www)我该如何解决这个问题?

nginx/1.13.5

nginx

1
推荐指数
1
解决办法
1665
查看次数

nginx http 重定向错误地将参数加倍(通过 AWS ELB)

例如,当我浏览

http://example.com/foo?x=1&y=2

nginx 将我重定向到

https://example.com/foo?x=1&y=2?x=1&y=2

现在,如果我继续重定向,我会得到

https://example.com/foo?x=1&y=2?x=1&y=2?x=1&y=2?x=1&y=2

它不断加倍参数,不知道我做错了什么。

我的 nginx 配置:

server {
  listen 80;
  listen 443 ssl;

  server_name {{ .SERVER_NAME }} www.{{ .SERVER_NAME }};

  ssl_certificate     /etc/ssl/nginx.crt;
  ssl_certificate_key /etc/ssl/nginx.key;

  if ($http_x_forwarded_proto != "https") {
      rewrite ^(.*)$ https://$server_name$REQUEST_URI permanent;
  }

  # Nginx will reject anything not matching /
  location / {
    # Reject requests with unsupported HTTP method
    if ($request_method !~ ^(GET|POST|HEAD|OPTIONS|PUT|DELETE|PATCH)$) {
      return 405;
    }

    # Only requests matching the whitelist expectations will
    # get sent to the application server …
Run Code Online (Sandbox Code Playgroud)

ssl nginx redirect amazon-web-services docker

1
推荐指数
1
解决办法
369
查看次数