【问题标题】:Nginx configuration changes are not taking place although nginx start, stop, reload is working fine尽管 nginx 启动、停止、重新加载工作正常,但 Nginx 配置更改未发生
【发布时间】:2016-03-18 03:01:54
【问题描述】:

我在 AWS 上有一个有效的 nginx 设置。

foo.domain.com 已经映射到 django 服务器。

我正在尝试将 url 从 foo.domain.com 更改为 foo777.domain.com。

但是nginx stop、reload、start成功后,新的url并没有生效。 Nginx 继续提供旧的 url foo.domain.com 而不是 foo777.domain.com

这是我到目前为止所做的。 我在 /etc/nginx/sites-available/foo 中将单词 foo 的所有实例更改为 foo777,它符号链接到 /etc/nginx/sites-enabled/foo。我可以在 vi 中打开符号链接文件并验证更改(foo->foo777)是否在配置中成功完成。

sudo service nginx stop && sudo service nginx reload && sudo service nginx start
 * Stopping nginx nginx                                                                                                                 [ OK ] 
 * Reloading nginx configuration nginx                                                                                                  [ OK ] 
 * Starting nginx nginx                                                                                                                 [ OK ] 

但是 nginx 仍然服务于 foo.domain.com 而不是 foo777.domain.com

我可以做 sudo service nginx stop 并且 foo.domain.com 成功停止;从浏览器检查。

我可以做 sudo service nginx start 并且 foo.domain.com 启动成功;从浏览器检查。

为了完整起见,我做了 sudo service nginx reload 并且成功完成且没有错误

我做了 sudo nginx -t 它报告了

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

我做了哪个 nginx,它会报告

/usr/sbin/nginx

我做了 nginx -V 并且它报告:

nginx version: nginx/1.2.6 (Ubuntu)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --with-pcre-jit --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.2.6/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.2.6/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.2.6/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.2.6/debian/modules/nginx-dav-ext-module

/etc/nginx/nginx.conf 如下所示:

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

    events {
        worker_connections 768;
        # multi_accept on;
    }

    http {

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

    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_disable "msie6";

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

/etc/nginx/sites-enabled/foo 看起来像这样:

server {
    listen       80;
    server_name  foo777.domain.com www.foo777.domain.com;

    access_log   /var/log/nginx/domain.access.log;
    error_log    /var/log/nginx/domain.error.log;
    root /home/user/foo/;

    location  /static/ {
        alias  /home/user/foo/static/;
    }

    location  / {
        proxy_pass            http://127.0.0.1:8700;
        proxy_redirect        off;
        proxy_set_header      Host             $host;
        proxy_set_header      X-Real-IP        $remote_addr;
        proxy_set_header      X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_read_timeout    7200;
        client_max_body_size  10m;
    }

    allow all;
}

一切看起来都很正常,除了 foo777.domain.com 没有被服务外,其他地方都没有报告错误。

我也重启了 AWS 实例,但也没有任何影响。 Nginx 继续提供旧网址。

在这方面的任何帮助将不胜感激。

谢谢。

__

@tedder42

编辑 1:

粘贴各种诊断命令的输出:

命令 1:

atd@atd-ub14:~$ curl -D - http://foo777.domain.com
curl: (6) Could not resolve host: foo777.domain.com

一段时间后的命令 1:

atd@atd-ub14:~$ curl -D - http://foo777.domain.com
curl: (7) Failed to connect to foo777.domain.com port 80: Connection timed out

命令2:

atd@atd-ub14:~$ curl -D - http://foo.domain.com
HTTP/1.1 301 MOVED PERMANENTLY
Server: nginx/1.2.6 (Ubuntu)
Date: Sat, 12 Dec 2015 06:38:30 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: http://foo.domain.com/login
Set-Cookie: sessionid=75eved1hfktbfrigiu063ny9dybltvma; httponly; Path=/

__

编辑 2:

netstat -tulpn 的输出 | grep nginx

netstat -tulpn | grep nginx
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      22932/nginx     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      22932/nginx  

【问题讨论】:

  • 你添加了dns记录吗?
  • 如果您致电curl -D - http://foo777.domain.com 会发生什么?运行它,然后编辑您的问题并将输出粘贴到它。如果你想让我再看一遍,请标记 (@tedder42) 我。
  • @LigoGeorge - 我试过了。符号链接是使用绝对路径创建的

标签: amazon-web-services nginx


【解决方案1】:

只需尝试在配置文件中产生一些语法错误并尝试使用 nginx -t,以确保您正在编辑正确的文件。

【讨论】:

    【解决方案2】:

    正如 Alexey Ten 所指出的,必须为 foo777 输入一个新的 dns 设置。这与 Google App Engine 的方式非常不同。感谢 Alexey 的帮助。

    【讨论】:

      猜你喜欢
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      • 2020-11-09
      • 1970-01-01
      • 2018-10-31
      • 2010-12-07
      • 1970-01-01
      相关资源
      最近更新 更多