LoginSignup
2
1

More than 1 year has passed since last update.

Apacheで80番以外のポート番号を指定する

Last updated at Posted at 2022-03-20

目的

Apacheを使用したWebサーバではデフォルトで80番のポート番号を使用している。
ポート転送をする際に、80番ポート以外を使用したい時が出てくるかと思います。
そこで、80番以外のポート番号を指定してWebサーバへアクセスする方法を記載する。

環境

windows10
VMware Workstation 16 Player
CentOS7
Apache

前提

VMware Workstation 16 Player上に、CentOS7を構築し、Apacheがインストールおよび起動している状態
http://IPアドレス/へアクセスすると以下の画面が表示される
※IPアドレスはコマンドip aで確認できる
image.png

手順

今回、指定するポート番号は10001とする。

httpd.confを編集する

1.viでhttpd.confを開き、Listen 80Listen 10001に修正する

httpd.confの開き方
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf
修正前
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80
修正後
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 10001

2.httpdをリスタートする

[root@localhost ~]# systemctl restart httpd

firewallの追加

1.ファイアウォールにポート番号10001を追加する

ポート番号追加
[root@localhost ~]# firewall-cmd --permanent --add-port=10001/tcp

2.ファイアウォールのリロード

[root@localhost ~]# firewall-cmd --reload

ポート番号10001でアクセスする

http://IPアドレス:ポート番号/でブラウザからアクセスをすると下記画面が表示されることを確認。
今回の例ではhttp://IPアドレス:10001/
image.png

参考サイト

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1