【问题标题】:Nginx overriding the default serverNginx 覆盖默认服务器
【发布时间】:2014-07-21 08:24:23
【问题描述】:

我正在尝试在 debian linux (RasPi) 上的 Nginx 下提供 webpy 应用程序。

如果我使用 80 以外的任何端口,我可以成功地为 webpy 应用程序提供服务。但是如果我尝试使用端口 80,则无法访问我的 webpy 应用程序,我将始终看到默认的“欢迎使用 Nginx”页面。

我已经尝试了所有我能想到的禁用默认页面并使用我的 webpy 应用程序覆盖它,但似乎没有任何效果。我已经删除了默认链接,并将文件从各自的目录中删除。我尝试在 nginx.conf 中直接指向 sites-enabled/webpy 而不是 sites-enabled/*。结果还是一样,如果我点击http://[ip-address]/,我会看到欢迎来到 nginx 页面。

我已经尝试了几次nginx -s reload 并停止/启动一切。并重新启动设备。

我如何覆盖它以便它在端口 80 上为我的 webpy 应用程序提供服务?

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/*; # I even tried pointing directly to webpy instead of *



}


#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;
#       }
#}

据我所知,这应该使 sites-enabled/ 内的任何东西都得到服务

我只有 1 个东西在启用站点/

$ ls -la
total 8
drwxr-xr-x 2 root root 4096 May 31 17:49 .
drwxr-xr-x 6 root root 4096 May 31 18:08 ..
lrwxrwxrwx 1 root root   32 May 31 17:49 webpy -> /etc/nginx/sites-available/webpy

这是指向可用站点/webpy 的链接

# webpy server
server{
  listen 80; # if I set this to 8080 then I can hit the app on that port.

  location / {
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param REMOTE_PORT $remote_port;
        fastcgi_param SERVER_ADDR $server_addr;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9002;
  }


  location /static/ {
      root /path/to/www;
      if (-f $request_filename) {
         rewrite ^/static/(.*)$  /static/$1 break;
      }
  }
}

我没有任何其他文件或sites-enabled/sites-avaialbe/ 中的链接我从这些文件夹中删除了默认文件。

【问题讨论】:

    标签: nginx web.py


    【解决方案1】:

    当你设置时

    listen 8080;
    

    运行

    sudo netstat -tlnp | grep nginx
    

    并查看 nginx 正在侦听的端口。此时它不应该在端口 80 上侦听。如果是试试

    sudo grep -rnIw "80" /etc/nginx
    

    如果 nginx 正在监听 80 端口,则必须在 /etc/nginx 下的某处声明它

    作为健全性检查,我还将完全停止 nginx 服务器

    sudo service nginx stop
    

    并查看是否有其他服务器正在为默认的 nginx 页面提供服务。

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 2016-03-24
      • 2017-09-10
      • 2020-03-19
      • 1970-01-01
      • 1970-01-01
      • 2015-09-07
      • 2015-06-19
      • 2016-05-06
      相关资源
      最近更新 更多