标签: nginx-location

无法将上游与 nginx 服务器中的文件夹映射

我想将我们的系统端口 82 映射到 127.0.0.1:8080/runningSite 并且我遇到了 nginx 配置异常。

upstream dev {
    server 127.0.0.1:8080/runningSite;
}
server {
    rewrite_log on;
    listen [::]:81;
    server_name localhost;

    location / {
        proxy_pass  http://dev;
        proxy_set_header Host $http_host;
    }

}
Run Code Online (Sandbox Code Playgroud)

例外 :

nginx: [emerg] invalid host in upstream "127.0.0.1:8080/runningSite" in C:\nginx -1.8.1/conf/nginx.conf:85
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我哪里我错了。

nginx winginx nginx-location

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

如何在 https NGINX 中将非 www 重定向到 www

我有一个与 Nginx 重定向相关的问题,您可以在下面看到配置。我的目标是从https://example.com重定向到https://www.example.com

我几乎在stackoverflow中查看了所有内容,但没有找到任何帮助。请帮我解决这个问题。我将提供有关我的 Nginx Web 服务器的所有必要信息。我希望你能帮我解决这个难题。

我的文件nginx.conf看起来像那里:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
  worker_connections 768;
}

http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;

  server_names_hash_bucket_size 64;

  include /etc/nginx/mime.types;
  default_type application/octet-stream;

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

  gzip on;
  gzip_static on;
  gzip_disable "msie6";

  gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 9;
  # gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xm$

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}
Run Code Online (Sandbox Code Playgroud)

我的档案 /etc/nginx/sites-enabled/example:

server { …
Run Code Online (Sandbox Code Playgroud)

nginx winginx nginx-location jwilder-nginx-proxy

3
推荐指数
2
解决办法
4136
查看次数

多个 Node JS Express 应用程序的 Nginx 多个位置

我有以下配置:

location / {
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-NginX-Proxy true;
  proxy_pass http://localhost:3000; # this is where our node js app runs at
  proxy_set_header Host $http_host;
  proxy_cache_bypass $http_upgrade;
  proxy_redirect off;
}
Run Code Online (Sandbox Code Playgroud)

哪个代理[SERVER_IP]/localhost:3000以便它基本上将所有内容路由到 node js 应用程序。

然后我继续编写了另一个 nodejs 应用程序,它在 port 上运行5000,而不是3000

location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://localhost:3000; # this is where our node js app runs at
      proxy_set_header Host $http_host;
      proxy_cache_bypass $http_upgrade;
      proxy_redirect …
Run Code Online (Sandbox Code Playgroud)

proxy nginx node.js nginx-location

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

Nginx:limit_conn 与上游 max_conns(在位置上下文中)

环境:Nginx 1.14.0(见dockerfile更多细节)。

要限制
服务器中特定位置的并发连接数,可以使用两种方法 - limit_conn(所有 ips 的第三个示例)
上游 max_conns
这两种方法的工作方式有区别吗?
有人可以解释或参考解释吗?

使用上游 max_conns 进行限制的示例:

http {
   upstream foo{
     zone upstream_foo 32m;
     server some-ip:8080 max_conns=100;
   }

   server {
    listen 80;
    server_name localhost;

    location /some_path {
       proxy_pass http://foo/some_path;
       return 429;
    }
   }  
}
Run Code Online (Sandbox Code Playgroud)

使用 limit_conn 进行限制:

http {

   limit_conn_zone $server_name zone=perserver:32m;

   server {
    listen 80;
    server_name localhost;

    location /some_path {
       proxy_pass http://some-ip:8080/some_path;
       limit_conn perserver 100;
       limit_conn_status 429;
    }
   }  
}
Run Code Online (Sandbox Code Playgroud)

nginx nginx-location

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

nginx 服务器对不同的子文件夹使用多个 fastcgi 后端

StackOverflow 上有多个问题如何使用具有不同 fastcgi 后端的子文件夹或类似的问题但没有任何工作正常 - 经过几个小时的尝试和阅读文档(可能缺少一个小细节)我放弃了。

我有以下要求:

  • 在 php 5.6 应用程序上/运行(fastcgi 后端127.0.0.1:9000
  • /crmphp 7.0 应用程序上运行,它必须相信它正在运行/(fastcgi 后端127.0.0.1:9001
  • 事实上还有很少的后端,但是有了这两个我可以自己制作它们

在尝试删除/crm前缀之前,我尝试首先为位置前缀定义单独的 php 上下文。但似乎我做错了什么,因为/crm每次都使用/.

我的实际精简配置删除了所有不相关的内容和所有失败的测试:

server {
    listen       80;
    server_name  myapp.localdev;

    location /crm {
        root       /var/www/crm/public;
        index      index.php;
        try_files  $uri /index.php$is_args$args;

        location ~ \.php$ {
            # todo: strip /crm from REQUEST_URI
            fastcgi_pass   127.0.0.1:9001; # 9001 = PHP 7.0
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    location / { …
Run Code Online (Sandbox Code Playgroud)

configuration fastcgi nginx nginx-location

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

如何操作 nginx 变量字符串

我正在尝试操作 nginx 变量。

我有一个变量名称 $user,其中包含一个 UPN,例如某人@example.com 我想设置另一个变量 $xuser;成为 $user 减去 @domain - 即某人。

这是在位置块中完成的,所以我认为我不能使用地图。

我已经尝试过这个,但 $xuser 似乎从未被设置:

if ($user ~* "(?<p>[aa-zZ]+)@example.com")
{
        set $xuser $p;
}
Run Code Online (Sandbox Code Playgroud)

nginx nginx-location

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

通过url参数根据locale在nginx上设置自定义404错误页面

我正在操作系统Nginx上运行最新的稳定版本GNU/Linux并拥有以下虚拟主机,我正在尝试setup custom localized 404 error pages avoiding if但我总是以重定向循环结束。

到现在为止,我只考虑下面的语言环境esen并且ca这是我得到的URL参数,始终旁域。类似的expected URLs are东西:

http://www.example.com/ca
http://www.example.com/ca/home
http://www.example.com/en
http://www.example.com/en/contact
Run Code Online (Sandbox Code Playgroud)

这是我的 nginx 服务器块:

server {
        listen          80;
        listen          [::]:80;
        server_name     example.com;
        root            /var/www/html/example_com;
        # By default, show Castilian index
        index           es/index.html;

        access_log      /var/log/nginx/example_com.access.log main;
        error_log       /var/log/nginx/example_com.error.log error;

        #Remove HTML Extension
        rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;

        # Remove trailing slash
        rewrite ^/(.*)/$ /$1 permanent;

        # Make sure Nginx knows what files to look …
Run Code Online (Sandbox Code Playgroud)

webserver nginx nginx-location

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

Nginx fastcgi_read_timeout 在特定位置

我想增加 nginx 位置级别的 fastcgi_read_timeout 。然而它不起作用。fastcgi_read_timeout 仍然是 6 而不是 10。我的配置文件是:

server {

listen 80;
listen [::]:80;
index index.php;

root /websites/somesite.org;
server_name somesite.org;
fastcgi_read_timeout 6s;

location / {
    try_files $uri /index.php$is_args$args;
}

location ~ ^/index\.php(/|$) {
    include fastcgi.conf;
    internal;
}

# increase timeout for charity uploads
location = /charities/charities/import/ {
    fastcgi_read_timeout 10s;
    try_files $uri /index.php$is_args$args;
}

# any other php extension should fail
location ~ \.php$ {
    return 403;
}
Run Code Online (Sandbox Code Playgroud)

}

但是,如果我添加 return 403; 代替 fastcgi_read_timeout 10s;它正确返回 403。我做错了什么?

nginx nginx-location

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

NGINX 未将调用从 React 应用程序路由到后端应用程序

我有一个 AWS Ubuntu 服务器,它托管在 127.0.0.1:4100 运行的 React 前端,并使用端口 127.0.0.1:1323 对 Go 应用程序进行 api 调用。我在配置文件中安装了 Nginx 并为这两个端口设置了代理通行证/etc/nginx/sites-available/default,但我只得到 Nginx 调用的前端。使用 chrome 检查检查 Go 应用程序为何不提供 React 应用程序的某些功能,我看到此错误

client.js:772 GET http://127.0.0.1:1323/api/ net::ERR_CONNECTION_REFUSED ERROR 错误:请求已终止 可能原因:网络离线、Access-Control-Allow-Origin 不允许 Origin、页面正在卸载等。

我究竟做错了什么?下面是我的默认配置文件

server { 

listen 80 default_server; 
listen [::]:80 default_server; 

server_name _; 

location / { 

proxy_pass http://127.0.0.1:4100; 

} 

location /api { 

proxy_pass http://127.0.0.1:1323/; 

 } 
}
Run Code Online (Sandbox Code Playgroud)

nginx nginx-location nginx-reverse-proxy nginx-config

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

在网站子目录中设置 phpMyAdmin

我有一个带有两个域的 NGINX Web 服务器,它还运行 phpMyAdmin。

phpMyAdmin 工作正常,我通过以下非 https 网址访问它:

公共 IP 地址/phpMyAdmin

这就是符号链接的设置方式:

sudo ln -s /usr/share/phpmyadmin/ /var/www/html
Run Code Online (Sandbox Code Playgroud)

有没有办法将 phpMyAdmin 指向网站的子目录?

例如,我想通过访问以下 URL 来访问 phpMyAdmin 登录页面:

domain1.com/phpMyAdmin/
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这个目标?domain1.com 已启用 https。所以它也可以保护我的 phpMyAdmin 登录。

服务器块与 NGINX 的默认块相同。我通过将其复制到文件夹中的domain.com 来创建一个新的配置文件/etc/NGINX/sites-available

唯一的变化是在serverroot路径标签中。其余一切都是默认的。

server domain1.com www.domain1.com;

root /var/www/domain1.com/html/
Run Code Online (Sandbox Code Playgroud)

我正在使用 certbot 来加密 SSL 证书。我的服务器块配置共享如下:

# Server Block Config for domain1.com
server {
    root /var/www/domain1.com/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name …
Run Code Online (Sandbox Code Playgroud)

symlink nginx phpmyadmin nginx-location

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