このサイトに接続できません。 ERR_CONNECTION_REFUSED - nginxがポート80でリッスンしない

このサイトに接続できません。 ERR_CONNECTION_REFUSED - nginxがポート80でリッスンしない

ローカルおよびリモートIPアドレスの要求を処理するために使用されるLEMPスタックを実行していますが、今は要求をまったく処理しません。リモート要求の処理が停止したら、仮想ホストを設定しようとします。この問題を解決しようとしましたが、現在はローカル要求も処理しません。 LAN またはインターネットからサイトにアクセスしようとすると、Chrome に次のエラー メッセージが表示されます。 「このサイトにアクセスできません... ERR_CONNECTION_REFUSED」

サーバーの内部IPアドレス、外部IPアドレス、ドメイン名をpingできますが、Webサイトはロードされません。また、コンピュータで直接実行するのではなく、SSHを介して実行します。これはネットワークの問題ではなく、構成の問題です。

これは私のサイトの設定ファイルです:/etc/nginx/sites-available/anneliesephotos.com

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /usr/share/nginx/ftp/lauren/anneliesephotos;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name anneliesephotos.com;
    # www.anneliesephotos.com;
    #server_name 99.104.137.87;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        # With php-cgi (or other tcp sockets):
        #fastcgi_pass 127.0.0.1:9000;
    }

    location ~ /\.ht {
            deny all;
    }
}

これは私の/etc/nginx/sites-available/defaultファイルの内容です。

server {
    listen 80;
    listen [::]:80;
    root /var/www/html;

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

    server_name _;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php$is_args$args;
    }
    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
            expires max;
            log_not_found off;
    }
}

Nanoのデフォルトファイルを見ると、「expire max;」、「log_not_found off;」行とその次の行の中括弧の左側には、ほとんどバグのように赤いブロックがあります。

/etc/nginx/nginx.conf ファイルは次のとおりです。

user www-data;
worker_processes 2;
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;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie_6";
    gzip_min_length 1100;

    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 image/svg+xml
    application/x-font-ttf font/opentype application/vnd.ms-fontobject;

    ##
    # Virtual Host Configs
    ##

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

/etc/nginx/sites-enabled には、/etc/nginx/sites-available/anneliesephotos フォルダへのシンボリックリンクがあります。

lrwxrwxrwx 1 root root   42 Nov 24 02:44 anneliesephotos -> /etc/nginx/sites-available/anneliesephotos

これを実行したときに、netstat -tlpnWebサイトの設定ファイルにそのようになっているにもかかわらず、ポート80が何らかの理由でリッスンしないことがわかりました。

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      702/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1211/sshd
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1326/mysqld
tcp6       0      0 :::21                   :::*                    LISTEN      1005/vsftpd
tcp6       0      0 :::22                   :::*                    LISTEN      1211/sshd

私が実行すると、nginx -t次のような結果が得られます。

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

を実行すると、service nginx status他の行と一緒に次の行が表示されます(「off」または「disabled」は含まれません)。

Active: active (running) since Sat 2018-11-24 10:47:48 UTC; 5h 38min ago

そのため、nginxが実行されており、設定ファイルの構文が正しいこと、特定のサイトの設定ファイルがポート80でリッスンしていると言い、設定ファイルが/ sites-enabledにシンボリックリンクされていることを知っています。

ベストアンサー1

結局、nginxを削除して再インストールして再構成しました。あまり再構成する必要はなく、anneliesephotos設定ファイルに数行を追加するだけです。しかし、それは問題を解決できませんでした。

ネットワーク外ではサイトをpingすることもできないことがわかりました。私のルーターをチェックしてみると、すべてのトラフィックがWebサーバーに到達することを許可していることがわかりますが、明らかにそうではありません。必要なプロトコルのみを許可するようにルーターを再構成しました。その後、ルータを再起動し、トラフィックが通過し始めました。

ウェブサイトを提供するためにnginxの再構成を完了しました。私も変わらなければなりません

try_files $uri $uri/ =404;

到着

try_files $uri $uri/ /index.php?q=$uri&$args;

今再び動作します。

おすすめ記事