私はTrisquel 8(Ubuntuベース)を実行しているデスクトップコンピュータでApache Webサーバーを実行しています。自分のローカルネットワーク上の他のコンピュータ/デバイスからサーバーにアクセスできるようにしたいのですが、どうすればよいかわかりません。
ApacheサーバーのローカルIPアドレスを使用して別のデバイスから接続しようとすると、ブラウザに次のエラーメッセージが表示されます。 MacのFirefoxでは、「接続できません」というメッセージが表示されます。 Firefoxはローカルホストサーバーに接続できません。 '。 Android携帯でDuckDuckGoブラウザを使用して接続しようとすると、「Webページが利用できません」というメッセージが表示されます。 Webページの場所は次のとおりです。http://ローカルホスト/net::ERR_CONNECTION_REFUSED' のためロードできません。
nmap
どのポートが開いているかを確認するには、いずれかの回答を使用することをお勧めします。次の結果が返されます。
$ nmap [LOCAL IP ADDRESS]
Starting Nmap 7.01 ( https://nmap.org ) at 2019-10-12 09:25 EDT
Nmap scan report for [LOCAL IP ADDRESS]
Host is up (0.00013s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
したがって、ポート80がhttpに対して開いていることを示しています。ローカルネットワークの他のシステムでこのシステムをpingすることができ、nmap出力に見られるように、ssh用に別のポートが開いていることにも言及する価値があります。私は数ヶ月間SSHを介してこのコンピュータに接続してきました。これを行うには、ちょうどssh-serverをインストールしましたが、すぐに動作します。
もしそうなら、sshが問題なく動作することを考えると、これはApache2設定(iptables /ファイアウォールとは対照的)に問題があることを意味しますか?
iptableの内容:
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:http ctstate NEW,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
apache2.confの内容:
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.
# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
# /etc/apache2/
# |-- apache2.conf
# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf-enabled
# | `-- *.conf
# `-- sites-enabled
# `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
# together by including all remaining configuration files when starting up the
# web server.
#
# * ports.conf is always included from the main configuration file. It is
# supposed to determine listening ports for incoming connections which can be
# customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
# directories contain particular configuration snippets which manage modules,
# global configuration fragments, or virtual host configurations,
# respectively.
#
# They are activated by symlinking available configuration files from their
# respective *-available/ counterparts. These should be managed by using our
# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
# their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
# the default configuration, apache2 needs to be started/stopped with
# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
# work with the default configuration.
# Global configuration
#
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE! If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"
#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
Mutex file:${APACHE_LOCK_DIR} default
#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5
# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log
#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn
# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
# Include list of ports to listen on
Include ports.conf
# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
# Require local
# Require ip 192.168.1
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.
# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Wordpressインスタンスを実行しようとしていますが、Apacheサーバーに書き込める必要があるため、AllowOverride All
以下のファイルが必要です。/var/www
私のローカルコンピュータのブラウザで「localhost」を使用してWebコンテンツにアクセスできるため、Apache2は確実に実行されています。また、systemctl status apache2
実行中であることを表示するには、次の手順を実行します。
~$ systemctl status apache2
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Thu 2019-10-10 20:01:44 EDT; 5min ago
Docs: man:systemd-sysv-generator(8)
Process: 1562 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/apache2.service
├─1621 /usr/sbin/apache2 -k start
├─1624 /usr/sbin/apache2 -k start
├─1625 /usr/sbin/apache2 -k start
├─1626 /usr/sbin/apache2 -k start
├─1627 /usr/sbin/apache2 -k start
├─1628 /usr/sbin/apache2 -k start
└─2102 /usr/sbin/apache2 -k start
Oct 10 20:01:42 lee-Desktop systemd[1]: Starting LSB: Apache2 web server...
Oct 10 20:01:42 lee-Desktop apache2[1562]: * Starting Apache httpd web server apache2
Oct 10 20:01:43 lee-Desktop apache2[1562]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Oct 10 20:01:44 lee-Desktop apache2[1562]: *
Oct 10 20:01:44 lee-Desktop systemd[1]: Started LSB: Apache2 web server.
コメントで提案したように試しましたが、netstat --inet -a | grep apache2
結果は返されませんでした。明らかにapache2が実行されている場合は、ポート80でリッスンする必要があるため、これは珍しい現象です。私は実行しnetstat -plunt | grep :80
、次のような結果を得ます。
$ sudo netstat -plunt | grep :80
tcp6 0 0 :::80 :::* LISTEN 1557/apache2
これはApacheが聞いていますが、何も聞こえないことを意味しますか?
同じ要求された仮想ホスト構成に関する限り、唯一のファイルは/etc/apache2/sites-enabled/
000-default.confであり、その内容は次のとおりです。
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
runningも試しましたが、tail -f /var/log/apache2/*.log
リモートシステムから接続しようとすると、ログには何も印刷されません。
それでは、接続をブロックする問題をどのように解決しますか?接続が拒否された理由とその理由を理解するのに役立つログはどこにありますか?
私はJacobが彼の答えで提案したことを試しましたが、残念ながら問題は解決しませんでした。他のアドバイスやご案内をいただきありがとうございます!
ベストアンサー1
以下を使用して他のデバイスから接続しようとするとローカルIPアドレスApacheサーバー
- サーバー上で root として実行される
ip addr
(または) コマンドの出力を公開します。ifconfig
- どちらかを表示してください。ローカルIPアドレス以下で接続しようとしています。その他のデバイスそれから。
- 各デバイスのLAN IPアドレスを表示します。その他のデバイス接続時に使用します。
その理由は次のとおりです。また見てくださいPSルーターおよびサーバー構成に関連する他の信じ難い可能性。
ApacheサーバーのローカルIPをブラウザに入力しましたが、何らかの理由で接続を試みてエラーが発生しました。
http://localhost/
アドレスウィンドウに表示します。
これは本当に悪い臭いがすると言った。ローカルIPアドレス接続に使用する方法が非常に間違っています。
- 別の説明:要求は正常に通過しましたが意味のないHTTPリダイレクトが発生しました。読書をスキップしてください。PS番号3.
もしローカルIPアドレス問題は、127.0.0.1
または::1
アドレス自体と非常によく似ており、これが問題の根本原因である可能性があります。なぜならこれは「実際の」IPアドレスではありません。...
IPv4アドレス
127.0.0.1
または短縮IPv6アドレス::1
方法この端末、ホスト名はlocalhost
常にそのアドレスの同義語としてローカルに定義されます。サーバー自体以外のデバイスでこのアドレスに接続しようとすると、ポート80に接続するように指示します。それ自体(サーバーシステムのポート80ではありません)
~から他の機器HTTP サーバー自体を実行しない場合、接続試行は確実に
RST
TCP 障害で終了します。接続が拒否されました。「ブラウザでエラーが発生しました。
回避策:正しい方法を使用する必要があります。LAN IPアドレス他のマシンから接続するとき:当然ダメlocalhost
、ダメ127.0.0.1
、ダメ::1
...
ifconfig
root でコマンドを実行します。サーバー上そして、名前のないブロックを見つけてくださいlo
。IPアドレスはというフィールドになりますinet addr:
。- サーバーがローカルネットワークに接続されている場合メタリックライン、使用するブロックの名前が指定され、
eth
その後に数字がeth0
続きます。 - サーバーがローカルネットワークに接続されている場合ワイヤレスで、使用するブロックの名前が指定され、
wlan
その後に数字がwlan0
続きます。 - 使用するブロック〜しなければならないまた、
RUNNING
ステータス(LAN接続が有効になっていて利用可能であることを示す)も含まれます。 - 問題の住所は次のとおりです。192.168.xx、10.xxx、または172.16.xx〜172.31.xxの範囲。
- サーバーがローカルネットワークに接続されている場合メタリックライン、使用するブロックの名前が指定され、
ブラウザを起動してみてください。サーバー上を押してから、手順1で見つけたIPアドレスをアドレスバーに入力し、を押しますEnter。
- ページが正しく表示されたら、次の手順に進みます。
- 存在するその他のデバイス、同じLAN(携帯電話ではない)。
- ブラウザの起動その他のデバイスをタップし、手順1で見つけたIPアドレスを入力してGoを押します。
- ページが正しく表示されるはずです。
PS
正しいIPアドレスを使用している場合は、次のようにこの問題の明確な理由がない可能性があります。
ホームルータは「仮想LAN」で構成されているか、ポート分離- これは、各LANポートと各無線LANデバイスを独自の小規模ネットワークに分離します。各デバイスは限られており、互いに接続できません。(そしてインターネットに直接アクセスすることのみ許可されます。)
- この構成では、理論的には各仮想LAN内各デバイスが割り当てられます。同じIPアドレス。したがって、「サーバーのIPアドレス」を別のデバイスに入力すると、「偶然に」結果がそのデバイスの独自のLAN IPアドレスと同じように接続されていることを示します。それ自体HTTPサーバーを実行していないので、接続が拒否されました。「間違い。
- この場合、ルータでポート分離と仮想LANオプションを無効にしてください。
ホームルータには、次のものを含めることができます。レイヤ3スイッチ機能を実行し、アクセス制御リスト(ファイアウォールなど)を構成する拒否するプライベート LAN IP アドレスへの「着信接続」、トラフィックソースに関係なく。
したがって、デバイスがサーバーに接続しようとすると、ルーター(またはスイッチ)がTCPを使用して傍受して応答するため
RST
、接続が拒否されました。「間違い。- この場合、インターネット/PPPoEで発生するトラフィックにのみ適用されるようにルーターのアクセス制御リストを変更するか、ローカルIPアドレス範囲に適切な例外を提供してください。
サーバーにHTTP 301/302リダイレクトを作成する何かがある可能性があります
http://localhost/
。これはあなたの理由を説明することができます。その他のデバイスlocalhost
実際のLAN IPアドレスを入力してもアドレスウィンドウに表示されます。今すぐ、最初のリクエストがうまく行われました。ただし、サーバーまたはサーバー側のスクリプトで発生した誤った構成/誤解のためにクライアントがリダイレクトされました
http://localhost/
。これは答えの主な部分に記載されている理由のために間違ったアドレスです。最終結果は「接続が拒否されました。「2番目の要求でエラーが発生し、
http://localhost/
アドレスバーにあります。これをデバッグするためにブラウザを使用しないでくださいこれは、HTTP 301リダイレクトがキャッシュされたためです。 GNU
wget
などのツールを使用してリクエストその他のデバイス、出力を注意深く見てください。リダイレクトのステータスが '下に表示されている場合接続が拒否されました。「エラー - そうであれば、ネットワークの問題ではなくサーバーの問題です。これが発生した場合は、サーバーがリダイレクトされる原因を見つけて修正する必要があります。
この Web ルートを別の場所から取得した場合、クライアントが非正規ホスト名を使用して Web ルートにアクセスすることが検出された場合、リダイレクトを引き起こす構成が含まれる可能性があります。 (これはあなたが行くときのように非常に一般的です。www.stackexchange.comすると、次にHTTP 301リダイレクトが作成されます。stackexchange.com)
Webアプリケーションが標準のホスト名が公正であると考えると、
localhost
誤って問題のあるリダイレクトを生成する可能性がありますhttp://localhost/
。この場合は、お客様
.htaccess
とアプリケーションの構成を具体的に確認してから、リダイレクトを無効にしてください。