NGINX的配置问题

时间:2017-06-02 18:59:41

标签: nginx webserver nagios

在使用apache多年后,我刚刚切换到Nginx。我正在改变一切,但我有一段时间这样做。我目前的问题是nagios。我可以访问nagios,但它的cgi部分似乎没有工作,我只是得到乱码输出。访问时我也没有被提示输入用户名/密码,这有点令人担忧。

我也在我的网络服务器上运行owncloud,这似乎正常。这是我的配置。任何帮助将不胜感激。

upstream php-handler {
    server 127.0.0.1:9000;
}

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

#SSL Configuration
server {
    listen 443 ssl;
    server_name www.<my_server>.com;

    ssl_certificate /etc/letsencrypt/live/www.<my_server>.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.<my_server>.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;

    include /etc/nginx/default.d/*.conf;

    root /mnt/Webserver/html;

    client_max_body_size 10G;
    fastcgi_buffers 64 4K;

    # ownCloud blacklist
    location ~ ^/owncloud/(?:\.htaccess|data|config|db_structure\.xml|README) {
        deny all;
        error_page 403 = /owncloud/core/templates/403.php;
    }

    location / {
        index index.html;
    }

    location /owncloud/ {
        error_page 403 = /owncloud/core/templates/403.php;
        error_page 404 = /owncloud/core/templates/404.php;

        rewrite ^/owncloud/caldav(.*)$ /remote.php/caldav$1 redirect;
        rewrite ^/owncloud/carddav(.*)$ /remote.php/carddav$1 redirect;
        rewrite ^/owncloud/webdav(.*)$ /remote.php/webdav$1 redirect;

        rewrite ^(/owncloud/core/doc[^\/]+/)$ $1/index.html;

        # The following rules are only needed with webfinger
        rewrite ^/owncloud/.well-known/host-meta /public.php?service=host-meta last;
        rewrite ^/owncloud/.well-known/host-meta.json /public.php?service=host-meta-json last;
        rewrite ^/owncloud/.well-known/carddav /remote.php/carddav/ redirect;
        rewrite ^/owncloud/.well-known/caldav /remote.php/caldav/ redirect;

        try_files $uri $uri/ index.php;
    }

    # Optional: set long EXPIRES header on static assets
    location ~* ^/owncloud(/.+\.(jpg|jpeg|gif|bmp|ico|png|css|swf))$ {
        expires 30d;
        access_log off;  # Optional: Don't log access to assets
    }

    #Nagios

    location /nagios {
        alias /usr/share/nagios;

        auth_basic "Nagios Access";
        auth_basic_user_file /etc/nagios/htpasswd.users;
        index index.php;
        autoindex off;
    }

    location ~ ^/nagios/(.*\.php)$ {
      auth_basic "Nagios Restricted Access (via nginx)";
      auth_basic_user_file /etc/nagios/passwd;

      root /usr/share/nagios/;
      rewrite ^/nagios/(.*) /$1 break;
      fastcgi_index index.php;
      include /etc/nginx/fastcgi_params;
      fastcgi_param SCRIPT_FILENAME /usr/share/nagios$fastcgi_script_name;
      fastcgi_pass php-handler;
    }

    location ~ ^/nagios/(.*\.cgi)$ {
        auth_basic "Nagios Restricted Access (via nginx)";
        auth_basic_user_file /etc/nagios/passwd;

        root /usr/lib64/nagios/cgi;
        rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
        include /etc/nginx/fastcgi_params;
        fastcgi_param AUTH_USER $remote_user;
        fastcgi_param REMOTE_USER $remote_user;
        fastcgi_param SCRIPT_FILENAME /usr/lib64/nagios/cgi$fastcgi_script_name;
        fastcgi_pass php-handler;
    }

    location ~ \.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_pass php-handler;
    }
}

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我明白了。这是我的新配置。感谢。

private int countNodes(Node<E> localRoot, int count) {
    if (localRoot == null) 
        return count;     
    count++; // Visit root
    count = countNodes(localRoot.left, count); // Preorder-traverse (left)
    count = countNodes(localRoot.right, count); // Preorder-traverse (right)
    return count;
}

public int countNodes() {
   return countNodes(root, 0);
}