标签: nginx-location

nginx 在“set”指令中设置了无效数量的参数

我正在使用 nginx 文档中描述的 set 指令,但我不断收到此错误:

nginx_1     | 2016/09/13 15:06:08 [emerg] 8#8: invalid number of arguments in "set" directive in /etc/nginx/conf.d/default.conf:9
nginx_1     | nginx: [emerg] invalid number of arguments in "set" directive in /etc/nginx/conf.d/default.conf:9
Run Code Online (Sandbox Code Playgroud)

默认.conf:

server {
    set $dn "foo.dnsalias.net";
    ...
}
Run Code Online (Sandbox Code Playgroud)

我试过带引号和不带引号,没有任何变化。

我正在使用 nginx 版本 1.10.1

有谁知道问题是什么?

nginx nginx-location

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

Nginx - 在其他目录和PHP中使用root的位置

我尝试使用Nginx设置类似"Apache Alias"的位置,但我无法在此文件夹中处理PHP脚本.

这是我的文件夹结构(适用于Dev环境):

/var/www
+-  dev/public/ <-- This is my normal Web root : "/"
|   +- assets/
|   |  +- app.css
|   |  +- app.js
|   |
|   +-  index.php
|   +-  favicon.png
|    
+-  cut/public/ <-- This must like an "Apache Alias" : "/cut"
    +- assets/
    |  +- app.css
    |  +- app.js
    |
    +-  index.php
    +-  other_other_file.php (why not)
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的解决方案,但没有一个能正常工作.

这是我最好的Nginx配置:

server {
    listen   80;

    server_name _;
    root  /var/www/dev/public/;
    index index.php index.html;
    autoindex on;

    # Logs
    rewrite_log on; …
Run Code Online (Sandbox Code Playgroud)

php nginx nginx-location

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

在nginx中的位置添加前缀

我想添加一个带有前缀的位置,以便我的应用程序类似于不带斜线的位置,

例如:

server_name mydomain.com
location /{
   proxy_pass http://127.0.0.1:8000;
}
Run Code Online (Sandbox Code Playgroud)

通过上面的配置,该应用程序可以正常工作,但是我可以将多个应用程序用于同一个域,且其前缀如mydomain.com/app1;mydomain.com/app2

现在对于上面的我有一个类似下面的配置,

server_name mydomain.com
location /app1/{
 proxy_pass http://127.0.0.1:8000;
}
Run Code Online (Sandbox Code Playgroud)

但这不是加载我所有的静态文件,如css / js等,并且应用程序无法正常工作,请您帮我。

nginx winginx nginx-location

5
推荐指数
0
解决办法
718
查看次数

如何在该位置使用Nginx Regexp

该Web项目将静态内容放入一些/ content / img文件夹中。网址规则是:/ img / {some md5}但在文件夹中的位置:/ content / img / {前两位数字} /

url:      example.com/img/fe5afe0482195afff9390692a6cc23e1
location: /www/myproject/content/img/fe/fe5afe0482195afff9390692a6cc23e1
Run Code Online (Sandbox Code Playgroud)

此nginx位置是正确的,但不安全(符号点在regexp中不好):

        location ~ /img/(..)(.+)$ {
               alias $project_home/content/img/$1/$1$2;
               add_header Content-Type image/jpg;
         }
Run Code Online (Sandbox Code Playgroud)

下一个位置更正确,但不起作用:

        location ~ /img/([0-9a-f]\{2\})([0-9a-f]+)$ {
               alias $project_home/content/img/$1/$1$2;
               add_header Content-Type image/jpg;
         }
Run Code Online (Sandbox Code Playgroud)

帮助我查找错误以获取更正确的Nginx位置。

regex nginx nginx-location

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

Nginx“位置〜”。vs“位置〜* \”。

以下三个指令之间有区别吗?

location ~* \.(png)$ {
  expires max;
  log_not_found off;
}

location ~ \.(png)$ {
  expires max;
  log_not_found off;
}

location ~ .(png)$ {
  expires max;
  log_not_found off;
}
Run Code Online (Sandbox Code Playgroud)

预先感谢您抽出宝贵的时间。

php linux nginx server nginx-location

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

如何在 nginx 中使用尾部斜杠配置重定向到 url?

我想将不带斜杠的 URL 重定向到带有斜杠的路径。所以/some-url/some-url/

其余的网址,例如

  • /some-url.xml
  • /一些网址?
  • /some-url?q=v
  • /一些网址/

应该保持不重定向。

我发现这篇文章https://www.ateamsystems.com/tech-blog/nginx-add-trailing-slash-with-301-redirect-without-if-statements/,其中作者建议使用以下规则:

location ~ ^([^.\?]*[^/])$ {
   try_files $uri @addslash;
}

location @addslash {
    return 301 $uri/;
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这并没有真正起作用。因为 url /some-url?q=v被重定向到/some-url/

您能否建议如何更改正则表达式以使其工作?

url nginx canonical-link nginx-location

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

Nginx只允许root和api位置

我有一台服务器配置为我的服务器的反向代理.我想拒绝所有请求,除了两个位置,一个用于root,另一个用于api root.

所以服务器应该只允许对给定路径的请求

example.com/ (only the root)
example.com/api/ (every url after the api root)
Run Code Online (Sandbox Code Playgroud)

预期的行为是服务器应该拒绝以下所有可能性.

example.com/location
example.com/location/sublocation
example.com/dynamic-location
Run Code Online (Sandbox Code Playgroud)

我目前的nginx配置,

server {

   # server configurations

   location / {

        # reverse proxy configurations

    }

}
Run Code Online (Sandbox Code Playgroud)

如何设置此配置?

webserver web-hosting nginx access-control nginx-location

5
推荐指数
2
解决办法
4168
查看次数

NGINX 反向代理和 Access-Control-Allow-Origin 问题

我正在配置一个NGINX Reverse Proxy.

在浏览器上我去:
客户端网址: https : //www.hollywood.com

那么上面的网页需要做的请求是:
server url: https://server.hollywood.com/api/auth/login

这是对应的配置server.hollywood.com

server {
    listen 443 ssl;
    server_name             server.hollywood.com;
    # add_header 'Access-Control-Allow-Origin' "https://www.hollywood.com" always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
    ssl_certificate         ../ssl/lets-encrypt/hollywood.com.crt;
    ssl_certificate_key     ../ssl/lets-encrypt/hollywood.com.key;
    location /
    {
        proxy_pass http://localhost:9201;
        include "../proxy_params.conf";
    }
}
Run Code Online (Sandbox Code Playgroud)

实验一:

Access-Control-Allow-Origin注释掉该行后,当我访问:
客户端网址: https : //www.hollywood.com

我在浏览器控制台上收到以下错误(在我的例子中是 Chrome):

POST https://server.hollywood.com/api/auth/login/local 502 (Bad Gateway)
(index):1 Failed to load https://server.hollywood.com/api/auth/login/local: No 'Access-Control-Allow-Origin' header …
Run Code Online (Sandbox Code Playgroud)

reverse-proxy nginx nginx-location nginx-reverse-proxy nginx-status

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

NGINX 健康检查需要上游

我有一个位置,如:

location / {
set $api_name "Web";

proxy_intercept_errors on;

set $upstream upstream_a;

if ( $kms_in_cookie != "not_set" ) {
    set $upstream $kms_in_cookie;
}

if ( $upstream_in_cookie != "not_set" ) {
    set $upstream $upstream_in_cookie;
}

if ($cookie_zak != "") {
    set $upstream upstream_b;
}

proxy_pass http://$upstream;

health_check uri=/healthcheck  interval=30 fails=3 passes=3;}
Run Code Online (Sandbox Code Playgroud)

一旦我重新启动我的 NGINX,它就失败了:

nginx: [emerg] health check requires an upstream in
Run Code Online (Sandbox Code Playgroud)

有没有人对此有任何想法?这个错误是什么意思?

nginx nginx-location

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

nginx 如何在 try_files 中处理 =404 回退

我有一个示例 Web 服务器,在 www 目录中只有一个 index.html 文件。我可以使用以下配置设置 nginx:

location /subfolder {
     alias /data/www;
     try_files $uri $uri/ /index.html;
}
Run Code Online (Sandbox Code Playgroud)

In browser I can see correct response on my local domain test.local/subfolder, also test.local/subfolder/something returns a default nginx page (it is normal because root is not set)

if I change a configuration to

location /subfolder {
     alias /data/www;
     try_files $uri $uri/ /index.html =404;
}
Run Code Online (Sandbox Code Playgroud)

response to test.local/subfolder is still correct, but test.local/subfolder/something and all URI with /subfolder prefix return a index.html …

nginx nginx-location

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