0

我的 nginx 上有一个带有一些虚拟主机的 Debian 9 服务器。我使用letsencrypt通配符并为teampeak配置了一些工具,如webmin、monitorix和一个用于机器人的webinterface。

我为每个子域创建了一个 .conf 文件。

在主页 home.website.net 上没有问题。它只是带有图片和文本的 html,没有 php 或其他东西。

Webmin 也可以正常工作,sinusbot 和 monitorix 不行。

这是我的配置:

root@host:~# cat /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

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;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # 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/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

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

接下来是默认主机,可以正常工作:

root@host:~# cat /etc/nginx/sites-available/default

# Default server configuration
#
server {

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.php ;

        server_name home.website.net 192.168.1.16 XXX.XXX.XXX.XXX;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
            # fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            fastcgi_pass 127.0.0.1:9000;
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~ /\.ht {
                deny all;
        }


        listen 443 ssl http2; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/website.net/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/website.net/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server  {
        listen 80;
        listen [::]:80;
        server_name home.website.net 192.168.1.16 XXX.XXX.XXX.XXX;
        # enforce https
        return 301 https://$host$request_uri;
}

这是第一个不起作用的子域 sinusbot:

root@host:~# cat /etc/nginx/sites-available/sinusbot.conf
server {
        listen 80;
        listen [::]:80;
        server_name sinusbot.website.net;
        access_log  /var/log/nginx/sinusbot.access.log;
        error_log   /var/log/nginx/sinusbot.error.log;
        return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    access_log  /var/log/nginx/sinusbot.access.log;
    error_log   /var/log/nginx/sinusbot.error.log;
    server_name sinusbot.website.net;
    ssl on;
    ssl_certificate /etc/letsencrypt/live/website.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/website.net/privkey.pem;
    client_max_body_size 100M;

        location ~ \.php$ {
            # fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            fastcgi_pass 127.0.0.1:9000;
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME 
            $document_root$fastcgi_script_name;
        }

        location ~ /\.ht {
                deny all;
        }

        location / {
                proxy_pass      https://127.0.0.1:8087;
                proxy_redirect  off;

                #Proxy Settings
                proxy_redirect     off;
                proxy_set_header   Host $host:$server_port;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  
                $proxy_add_x_forwarded_for;

                proxy_max_temp_file_size 0;
                proxy_connect_timeout      90;
                proxy_send_timeout         90;
                proxy_read_timeout         90;
                proxy_buffer_size          128k;
                proxy_buffers              32 32k;
                proxy_busy_buffers_size    256k;
                proxy_temp_file_write_size 256k;
                }
}

第二个(monitorix)具有相同的配置,但具有另一个端口和子域。在这两个上我都得到一个 502 Bad Gateway 并且在日志文件中出现以下错误:

访问日志:

192.168.1.1 - - [10/Jun/2018:20:22:01 +0200] "GET / HTTP/2.0" 502 638 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36"
192.168.1.1 - - [10/Jun/2018:20:22:01 +0200] "GET /favicon.ico HTTP/2.0" 502 638 "https://sinusbot.website.net/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36"

错误日志:

2018/06/10 20:22:22 [error] 18522#18522: *51 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.1, server: sinusbot.website.net, request: "GET / HTTP/2.0", upstream: "https://127.0.0.1:8087/", host: "sinusbot.website.net"
2018/06/10 20:22:22 [error] 18522#18522: *51 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.1, server: sinusbot.website.net, request: "GET /favicon.ico HTTP/2.0", upstream: "https://127.0.0.1:8087/favicon.ico", host: "sinusbot.website.net", referrer: "https://sinusbot.website.net/"

最后,Webmin ngnix 配置可以正常工作:

root@host:~# cat /etc/nginx/sites-available/webmin.conf
server {
        listen 80;
        listen [::]:80;
        server_name webmin.website.net;
        access_log  /var/log/nginx/webmin.access.log;
        error_log   /var/log/nginx/webmin.error.log;
        return 301 https://$host$request_uri;
}

server {
        server_name webmin.website.net;
        listen 443 ssl http2;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/website.net/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/website.net/privkey.pem;
        access_log off;
        error_log off;
        location /RequestDenied {
        return 418;
        }

        location / {
                proxy_pass      https://127.0.0.1:10000;
                proxy_redirect  off;

                #Proxy Settings
                proxy_redirect     off;
                proxy_set_header   Host $host:$server_port;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

                proxy_max_temp_file_size 0;
                proxy_connect_timeout      90;
                proxy_send_timeout         90;
                proxy_read_timeout         90;
                proxy_buffer_size          128k;
                proxy_buffers              32 32k;
                proxy_busy_buffers_size    256k;
                proxy_temp_file_write_size 256k;
                }
}

有任何想法吗?

4

1 回答 1

0

因此,由一位同事和我自己解决:

        location ~ \.php$ {
        # fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        fastcgi_pass 127.0.0.1:9000;
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME 
        $document_root$fastcgi_script_name;
    }

该块告诉您,您应该显示一个具有此配置的 php 文件,并且在此之后的部分,其中定义,网站在哪里,将被忽略。

于 2018-06-11T09:40:09.537 回答