AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-95568

jwerre's questions

Martin Hope
jwerre
Asked: 2018-04-17 18:32:12 +0800 CST

为什么我的 404 返回 200 状态码?

  • 0

不知道为什么,但我所有的错误页面都以 200 响应。这对我来说有点奇怪,这些页面存在但它们不应该有相应的状态代码吗?如何让 Nginx 使用 404 状态码呈现我的 404 页面?

例如:

▶ curl -I http://example.com/404
HTTP/1.1 200 OK <<--------------------------- WTF! THIS SHOULD BE 404!!
Server: nginx/1.8.0
Date: Tue, 17 Apr 2018 02:24:04 GMT
Content-Type: text/html; charset=UTF-8
...

这是我的配置的相关部分:

server {

listen 80 default_server;

server_name example.com;
root /var/www/example/static;
index index.html;

try_files $uri $uri/ $uri.html =404;

# error pages
error_page 400 =400 /400; # bad request
error_page 401 =401 /401; # unauthorized
error_page 403 =403 /403; # forbidden
error_page 404 =404 /404; # not found
error_page 408 =408 /408; # timeout
error_page 500 502 503 504 =500 /500; # error

} 

在文档中是状态:

...可以更改响应代码...使用“=response”语法

该页面确实存在,但error_page在配置中设置了一个应该更改该页面的状态。例如,如果您使用curlGoogle 的 404,您会得到正确的结果:

curl -I https://www.google.com/404
HTTP/2 404  <<--------------------------- Ahhh, much better.
content-type: text/html; charset=UTF-8
referrer-policy: no-referrer
content-length: 1564

我需要我的 404 页面来生成 404 状态代码,因为我从我的应用程序的其他部分重定向到它。这对人类来说很好,但对机器不利,因为重定向会产生 302,然后是 200 而不是 404。

nginx
  • 2 个回答
  • 7457 Views
Martin Hope
jwerre
Asked: 2017-04-05 18:15:48 +0800 CST

在 AWS ELB 后面使用 NGINX 剥离 www

  • 2

我正在尝试从我的请求 URL 中删除 www,但是当我将以下内容添加到我的 nginx 配置中时,我的 AWS ELB 运行状况检查失败。

server {
    listen 80;
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
}

知道可能导致问题的原因吗?这是我的配置的其余部分:

server {

    listen 80;

    server_name .example.com;
    root /var/www/static;
    index index.html;

    try_files $uri.html $uri $uri/ =404;

    charset UTF-8;

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

    # ELB test route
    location /test {
        add_header X-Robots-Tag noindex;
        default_type text/plain; 
        return 200 'success';
    }

    # Redirect any request http request that come from AWS ELB to https
    if ($http_x_forwarded_proto = "http") {
        return 301 https://$server_name$request_uri;
    }
}

这是我的健康检查设置:

aws 目标组健康检查

nginx
  • 2 个回答
  • 1766 Views
Martin Hope
jwerre
Asked: 2017-01-26 13:05:27 +0800 CST

多台服务器,一个配置文件

  • 2

我有多个应用程序在不同的服务器上运行,但它们都需要相同的配置文件(其中包含敏感信息)。目前,我只是在我所有的服务器上加载配置文件,但它的可扩展性不是很好,当我想进行更改时会很痛苦。

为多台服务器提供单一配置的安全解决方案有哪些?这些是 ec2 实例,所以如果有一个 AWS 解决方案可以让我更容易,我会全力以赴。

我目前倾向于的解决方案是加密配置并将其放在 AWS S3 上,然后使用 AWS Key Management Service (KMS) 在服务器端解密。任何其他想法将不胜感激。

configuration application amazon-web-services
  • 1 个回答
  • 191 Views
Martin Hope
jwerre
Asked: 2016-06-10 08:08:11 +0800 CST

Nginx 别名不起作用

  • 0

我正在尝试将 location 的所有流量传递^/[a-z0-9]{24}$给不同根目录的 index.html。我的配置设置如下:

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

server {

    listen 443 ssl;

    server_name example.com;
    root /Users/me/sites/store_front/static;
    index index.html;

    try_files $uri $uri/ $uri.html =404;

    location ~ "^/[a-z0-9]{24}$" {
        alias /Users/me/web_app/static;
        try_files $uri index.html;
    }
}

出于某种原因,当我卷曲这个网址时,我得到一个 404:

$ curl -I https://example.com/55c898e7faa137f42409d403

HTTP/1.1 404 Not Found
Server: nginx/1.8.0
Content-Type: text/html; charset=UTF-8
Content-Length: 168
Connection: keep-alive

有谁知道如何让这个别名工作?

更新:

需要注意的是,我需要 index.html 中的所有相对 url 才能正确加载:

<link href="/styles/main.css" rel="stylesheet" type="text/css"
<script src="/javascript/main.js"></script>

这些文件实际上存在于web_app目录中,但 nginx 尝试从中加载它们store_front

谢谢

nginx alias
  • 1 个回答
  • 1651 Views
Martin Hope
jwerre
Asked: 2015-02-10 07:02:21 +0800 CST

绑定:无法分配请求的地址

  • 9

我最近从 Rackspace 切换到 AWS,并且正在使用freegeopip设置一个简单的地理定位服务器。虽然以下命令在新的 Rackspace 服务(Ubuntu)上完美运行,但我无法在 AWS 上工作(尝试过 Red Hat 和 Ubuntu)。这是我用来设置它的代码:

curl -s https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz | tar -C /opt -zx
export GOPATH=$HOME
export GOROOT=/opt/go
export PATH=$PATH:/opt/go/bin
go get github.com/fiorix/freegeoip/cmd/freegeoip
$GOPATH/bin/freegeoip -addr="<MY IP ADDRESS>:8080"

正如我所说,这在我的 Rackspace 实例上非常有效,但 AWS 给了我这个错误:

listen tcp <MY IP ADDRESS>:8080: bind: cannot assign requested address

我用 netstat 检查了这个端口,上面没有运行任何东西。我不知道为什么会收到此错误。有任何想法吗?

amazon-web-services
  • 2 个回答
  • 17172 Views
Martin Hope
jwerre
Asked: 2014-04-24 07:41:35 +0800 CST

我的网络服务器上有多少个连接?

  • 0

我有一个运行几个服务器的 Rackspace 负载平衡器。在我更新我的站点并重新启动 Web 服务器之前,我耗尽了与其中一台服务器的连接,但我不确定服务器何时完全耗尽。有没有办法告诉?

ubuntu
  • 1 个回答
  • 66 Views
Martin Hope
jwerre
Asked: 2013-10-29 09:54:30 +0800 CST

如何强制 NGINX 加载新的静态文件?

  • 29

我最近向一个网站推送了一个重大更新,但我遇到了一个问题,有些人无法登录,因为他们的浏览器正在加载旧的javascript 文件。我做过的一些事情包括:

  • 缓存破坏所有 javascript 文件
  • sendfile off在 nginx.conf 中设置
  • expires 1s在 mysite.conf 中设置
  • 显式设置 Cache-Control 标头:add_header Cache-Control no-cache;

下面是我的 nginx 配置文件。任何帮助将非常感激。

/etc/nginx/sites-enabled/mysite.conf

proxy_cache_path  /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;

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

server {

        # listen for connections on all hostname/IP and at TCP port 80
        listen *:80;

        # name-based virtual hosting
        server_name www.mysite.com;

        # location of the web root for all static files (this should be changed for local development)
        root /var/mysite.com/static;

        # redirect http requests to https
        if ($http_x_forwarded_proto = "http") {
            rewrite  ^/(.*)$  https://www.mysite.com/$1 permanent;
        }

        # error pages
        error_page 403 /errors/403.html;
        error_page 404 /errors/404.html;
        error_page 408 /errors/408.html;
        error_page 500 502 503 504 /errors/500.html;  

        # error and access out
        error_log /var/log/nginx/error.mysite.log;
        access_log /var/log/nginx/access.mysite.log;

        # use Nginx's gzip static module
        gzip_static on;
        gzip_types application/x-javascript text/css;

        location / {

            # redefine and add some request header lines which will be passed along to the node server
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_set_header X-Forwarded-Proto $scheme;

            # set the address of the node proxied server
            proxy_pass http://127.0.0.1:9001;

            # forbid all proxy_redirect directives at this level
            proxy_redirect off;
        }

        # do a regular expression match for any files ending in the list of extensions

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|xml|html|htm)$ {

            # clear all access_log directives for the current level
            access_log off;
            add_header Cache-Control no-cache;
            # set the Expires header to 31 December 2037 23:59:59 GMT, and the Cache-Control max-age to 10 years
            expires 1s;
        }

}

/etc/nginx/nginx.conf

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

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile off;
    tcp_nopush off;
    tcp_nodelay off;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
nginx
  • 7 个回答
  • 137489 Views
Martin Hope
jwerre
Asked: 2013-04-26 16:53:00 +0800 CST

使用负载均衡器后面的 ngnix 将 http 重写为 https

  • 13

我正在使用 Rackspace 负载平衡器,它使我能够在管理面板内设置我的 ssl 密钥/pem。一切正常,我可以同时使用 http 和 https 协议。但是,如果我尝试使用以下方法将 http 重定向到 https:

server{
  listen *:80;
  server_name mydomain.com www.mydomain.com; 
  rewrite ^ https://mydomain.com$request_uri? permanent;

...我得到一个重定向循环。我意识到我没有在监听端口 443,但那是因为负载均衡器为我处理了它。我也试过包装重写if ($scheme ~* http){但无济于事。

我问题的另一部分是我想从 url 中删除 www,我可以通过一次重写来做到这一点吗?上面的重写不应该也解决这个问题吗?

谢谢你的帮助!

nginx
  • 3 个回答
  • 18598 Views
Martin Hope
jwerre
Asked: 2013-02-20 12:11:03 +0800 CST

使用单个重定向删除 www 和 .html

  • 1

我遇到一个问题,如果用户键入:

www.myurl.com/page.html

他们首先被重定向到

myurl.com/page.html

然后到

myurl.com/page

这是因为我的 conf 文件中有以下内容

    #remove www from url
    if ($host ~* ^www\.(.*)) {
        set $remove_www $1; 
        rewrite ^(.*)$ http://$remove_www$1 permanent;
    }

    location  /{

            # removes .html extension
            if ($request_uri ~ \.html($|\?)) {
                    rewrite ^(.+)\.html$ $1 permanent;
            }
    }

我的问题:

有没有办法消除第一个重定向,这样如果用户键入www.mysite.com/page.html,他们将直接重定向到mysite.com/page

nginx
  • 1 个回答
  • 84 Views
Martin Hope
jwerre
Asked: 2012-10-04 10:07:05 +0800 CST

在 Amazon EC2 上设置 nginx Web 服务器时遇到问题

  • 0

d 我登录到我的 EC2 控制台创建了一个新实例并为其附加了一个 Elastice IP。然后我登录到服务器并安装了 Nginx:

$ sudo apt-get install nginx
$ sudo /etc/init.d/nginx start
$ Starting nginx: nginx.

当我导航到弹性 IP(或公共 DNS)时,我什么也得不到。默认设置应该足以显示默认的 Nginx 欢迎页面,对吗?我碰壁了,不知道下一步该怎么做。我们欢迎所有的建议?

我没有碰过它,但这是我的默认 nginx.conf:

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

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

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

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

访问日志或错误日志中没有任何内容,我还确保 nginx 正在运行:

ps -ax | grep nginx
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
4305 ?        Ss     0:00 nginx: master process /usr/sbin/nginx
4306 ?        S      0:00 nginx: worker process
4307 ?        S      0:00 nginx: worker process
4308 ?        S      0:00 nginx: worker process
4309 ?        S      0:00 nginx: worker process
nginx
  • 1 个回答
  • 620 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve