Squidによるリバーシプロキシをやってみた結果503エラーとなり失敗して諦めました
photoshoplabにリバースプロキシの設定を使用と思いました。PhotoshoplabはApacheを使っているのでapacheを使ってできないか探してみました。
Squidを使ってリバースプロキシ設定
Squidというのを見つけました。これをつかってリバースプロキシができるとのことなので設定してみました。参考サイトはCentOS6][Squid] リバースプロキシでキャッシュサーバにするのページになります。
インストール
[c]
yum install -y squid
[/c]
インストールします。
[c]
#
# Recommended minimum configuration:
#
#acl manager proto cache_object
#acl localhost src 127.0.0.1/32 ::1
#acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localhost src 127.0.0.1/32
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
#acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
#acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
#acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
#acl localnet src fc00::/7 # RFC 4193 local private network range
#acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
#acl SSL_ports port 443
acl Safe_ports port 8080 # http
#acl Safe_ports port 21 # ftp
#acl Safe_ports port 443 # https
#acl Safe_ports port 70 # gopher
#acl Safe_ports port 210 # wais
#acl Safe_ports port 1025-65535 # unregistered ports
#acl Safe_ports port 280 # http-mgmt
#acl Safe_ports port 488 # gss-http
#acl Safe_ports port 591 # filemaker
#acl Safe_ports port 777 # multiling http
#acl CONNECT method CONNECT
#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
#http_access allow manager localhost
#http_access deny manager
http_access allow all
#http_access allow localhost
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
#http_access deny CONNECT !SSL_ports
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost
#http_access allow all
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
#http_access allow localnet
#http_access allow localhost
# And finally deny all other access to this proxy
#http_access deny all
# Squid normally listens to port 3128
#http_port 3128
http_port 8080 vhost
# We recommend you to use at least the following line.
hierarchy_stoplist cgi-bin ?
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256
cache_peer 127.0.0.1 parent 80 0 no-query originserver
cache_dir ufs /var/spool/squid 8000 32 512
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid
# Add any of your own refresh_pattern entries above these.
#refresh_pattern ^ftp: 1440 20% 10080
#refresh_pattern ^gopher: 1440 0% 1440
#refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 30 20% 3600
#ログファイル
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
access_log /var/log/squid/access.log combined
# HTTP_X_FORWARDED_FOR 環境変数には Unknown という値が入る
forwarded_for off
# HTTP_VIA 環境変数を unknown にする
visible_hostname unknown
# メモリを節約する
memory_pools off
[/c]
設定をします。設定が終わったら今度はapacheの設定をします。
Apacheの設定
[c]
vi /etc/httpd/conf.d/photoshoplab.conf
[/c]
バーチャルホストの設定をします。
[c]
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.photoshoplab.jp:8080/ retry=5
ProxyPassReverse / http://www.photoshoplab.jp:8080/
</IfModule>
[/c]
こんな感じに設定します。
503エラー
Apacheの再起動とSquidを起動すると503エラーになります。人生初の503エラーがでてちょっと嬉しいと思いながらなぜ今でる!?という感覚になりました。
原因
503エラーは過負荷やメンテナンスなどで起きるエラーですが、正直なぜ起きたのかわかりませんでした。調べて見たらもしかしてSELinuxが影響しているのではないかとなりました。
SELinuxが有効化か調べる
SELinuxが有効化か調べて見ました。
[c]
[root@localhost]# getenforce
Enforcing
[/c]
SELinuxが有効化でした。無効化するには以下のコマンドを使います。
[c]
[root@localhost ~]# setenforce 0
[root@localhost]# getenforce
Permissive ←無効化になりました
[/c]
無効化にしましたが、サーバーを再起動すると有効化されます。サーバーを再起動しても有効化されないようにするには以下のようにします。
[c]
#vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing ← disabledにします
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[/c]
治らない503エラー
SELinuxを無効にしても治りませんでした。そのため、今回は諦めました。
個人支援・寄付について
サイトラボでは個人支援・寄付を受けております。ご協力いただける方はお願いいたします。当サイトではビットコインで受け付けております。
- ビットコイン:3LHnADwZwUbic2L45EnVJEykiG6KfbqrwS