iT邦幫忙

0

apache 的openwebmail 如何強迫只能使用ssl連線?

sendmail+openwebmail+apache+mod_ssl

因為這台mail server沒有對外連線網頁的需要
只有webmail收發信的需求

覺得開80port 讓外部人員連進來收發信好像不是很安全
而且一堆攻擊都針對80port

所以才想改為用強迫使用ssl連線,但是連線的port不是443
是我隨便指定的一個port比如30000 port

我改了ssl.conf和httpd.conf裡的Listen改為30000port
但是重啟動apache後失敗

錯誤如下

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:38965
no listening sockets available, shutting down
Unable to open logs

請問要如何做才好呢?

fillano iT邦超人 1 級 ‧ 2010-08-28 08:31:47 檢舉
其實現在的selinux已經很方便了,能開的話還是建議儘量打開。有問題的話,看一下/var/log/messages,通常selinux的log都會提供詳細的資訊跟解決方法(透過sealert指令)。

很多人關掉selinux的理由,是因為安裝web應用程式碰到問題(我以前也是這樣)。其實對於web應用,通常也只要多學一個chcon指令就能應付,並不麻煩。
你好,因為自己對linux學習不精,只能半吊子作的給公司用
目前看起來還好,且有定時作備份,

因為公司用不能一直停擺..
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

10
Ray
iT邦大神 1 級 ‧ 2010-08-26 18:37:10
最佳解答

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:38965

上面已經寫出原因了啊:
你指定的 Port 39865, 已經被其他程式占用, 故 Apache 無法 Bind.

看更多先前的回應...收起先前的回應...

您好我是用這指令查看的,看起來好像沒有暫用到38965port
是否我弄錯了還是要用其它指令才對呢?

netstat -tunl t: tcp, u:udp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:783 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:38964 0.0.0.0:* LISTEN
tcp 0 0 123.456.78.999:53 0.0.0.0:* LISTEN

tcp 0 0 192.168.1.17:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN
udp 0 0 123.456.78.999:53 0.0.0.0:*
udp 0 0 192.168.1.17:53 0.0.0.0:*
udp 0 0 127.0.0.1:53 0.0.0.0:*

Ray iT邦大神 1 級 ‧ 2010-08-26 21:55:03 檢舉

def123452002提到:
tcp 0 0 0.0.0.0:38964 0.0.0.0:* LISTEN

這個蠻可疑的, 雖然只跟 Log 裡面的數字相差 1, 不過那也太湊巧了吧?.....

您要不要先換個離上面那些數字都很遠的 Port number 試試看?

fillano iT邦超人 1 級 ‧ 2010-08-26 22:04:53 檢舉

加個 -p 把行程也列出來就清楚了

您好,那是我的ssh port XD
因為一個用38964所以想說apache用38965比較好記

加了p之後的結果

<pre class="c" name="code">tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:783               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:6000                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:38964               0.0.0.0:*                   LISTEN      -
tcp        0      0 123.456.789.999:53           0.0.0.0:*                   LISTEN      -
<pre class="c" name="code">tcp        0      0 192.168.1.17:53             0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:53                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:953               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      -
udp        0      0 123.456.789.999:53           0.0.0.0:*                               -
udp        0      0 192.168.1.17:53             0.0.0.0:*                               -
udp        0      0 127.0.0.1:53                0.0.0.0:*  

其實我原本用38965不行,又改成30000也不行,不知道原因
所以只好上來請大家幫忙一下暈

Ray iT邦大神 1 級 ‧ 2010-08-26 23:10:54 檢舉

你的 conf 裡面, 是不是有 VirtualHost 的指令? 指令後面的 Port 有沒有跟著一起改?

您說我的httpd.conf嗎?沒有我沒做VirtualHost

指令後面的 Port 有沒有跟著一起改?
這句話是什麼意思?

fillano iT邦超人 1 級 ‧ 2010-08-26 23:52:08 檢舉

耶...加上 -p 的話,你要配合sudo,不然看不到行程資訊。

fillano iT邦超人 1 級 ‧ 2010-08-27 00:00:09 檢舉

作業系統?防火牆設定?/etc/services?

fillano iT邦超人 1 級 ‧ 2010-08-27 00:24:34 檢舉

如果你SELINUX有開的話,檢查/var/log/messages,應該會有相關資訊,長得像這樣:

<pre class="c" name="code">
...
Aug 27 00:13:53 hostname setroubleshoot: SELinux is preventing the httpd (httpd_t) from binding to port 30000. For complete SELinux messages. run sealert -l 1cdbb435-b7fc-44f2-8ced-5105ced5e185
...

你把sealert -l 1cdbb435-b7fc-44f2-8ced-5105ced5e185執行看看(後面的這一串代碼每次都不會一樣),裡面會有怎麼修改權限規則的提示,然後依照提示修改規則。

在我的系統(CentOS),如果selinux有開的話,就需要改/etc/services -> 改防火牆 -> 改selinux規則,才有辦法讓httpd去listen port 30000(或是其他port,也就是80及443之外的port)

我用root進的,應該不用sudo了

列出來的就是如
"加了p之後的結果"
那回應下面列出來的相同

centos5.4 selunux沒開,

防火牆有一個外部硬體的,(當然30000port有記得改)
只有用iptables自己寫(當然30000port有記得改)
httpd.conf=>Listen 80 加入#後 多加一行Listen 30000
ssl.conf=>Listen 443加入#後改為 多加一行Listen 300000
重啟httpd
出現
httpd: (98)Address already in use: make_sock: could not bind to address 0.0.0.0:30000
no listening sockets available, shutting down
Unable to open logs

/etc/server 裡面沒有30000這個字

抱歉,我剛沒仔細看 上面那個是沒有p的

<pre class="c" name="code">ctive Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      2032/dovecot
tcp        0      0 127.0.0.1:783               0.0.0.0:*                   LISTEN      2056/spamd.pid
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      2032/dovecot
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      31050/httpd
tcp        0      0 0.0.0.0:6000                0.0.0.0:*                   LISTEN      30406/X
<pre class="c" name="code">tcp        0      0 0.0.0.0:38964               0.0.0.0:*                   LISTEN      11986/sshd
tcp        0      0 123.456.789.999:53           0.0.0.0:*                   LISTEN      1978/named
tcp        0      0 192.168.1.17:53             0.0.0.0:*                   LISTEN      1978/named
tcp        0      0 127.0.0.1:53                0.0.0.0:*                   LISTEN      1978/named
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      17952/sendmail: acc
tcp        0      0 127.0.0.1:953               0.0.0.0:*                   LISTEN      1978/named
<pre class="c" name="code">tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      31050/httpd
udp        0      0 123.456.789.999:53           0.0.0.0:*                               1978/named
udp        0      0 192.168.1.17:53             0.0.0.0:*                               1978/named
udp        0      0 127.0.0.1:53                0.0.0.0:*                               1978/named
Ray iT邦大神 1 級 ‧ 2010-08-27 14:29:02 檢舉

def123452002提到:
httpd.conf=>Listen 80 加入#後 多加一行Listen 30000
ssl.conf=>Listen 443加入#後改為 多加一行Listen 300000

啊哈!! 找到了!!.....

只有 ssl.conf 需要改 port, httpd.conf 請維持原來的 80.....

只有 ssl.conf 需要改 port, httpd.conf 請維持原來的 80.....

這一行我不是開頭就有寫了嗎囧

我等等試試....Orz

不過這樣的作法,和我原本想要的好像不太相同
變成
http://it.com.tw/webmail

https://it.com.tw/webmail都可以連
不過https:變成30000 port而以

用戶是很皮的

要叫他們多打那幾個https://
感覺會要他們老命

若無強制變成只能用https的話,
他們一定打個
it.com.tw/webmail

能進就好了,反正有沒有安全問題也不關他們事

先試試行不行再說,以上抱怨毆飛

fillano iT邦超人 1 級 ‧ 2010-08-27 15:25:12 檢舉

你可以設置VirtualHost,讓從80埠跟30000埠進來的request map到不一樣的目錄,然後在80埠的預設目錄設定redirect到https的網址。

Ray iT邦大神 1 級 ‧ 2010-08-27 15:28:46 檢舉

def123452002提到:
這一行我不是開頭就有寫了嗎

因為手冊都只是叫大家去改 ssl.conf, 我沒有想到會有人去改 httpd.conf....暈

http://it.com.tw/webmail

https://it.com.tw/webmail都可以連
不過https:變成30000 port而以

這個結果才是正常的. 如果您不希望 User 從 Port 80 進來的話, 必須要在這裡做一個 Redirect 的小程式, 判斷進來的是 http 還是 https? 如果發現是 http 的話, 自動送出 redirect 指令給瀏覽器, 強迫他轉用 https....

這部分, 會寫網頁程式的人應該懂, 找人隨便寫個 .php 就能解決...
這裡也有些範例:
How to redirect browser to https (ssl) in php

Ray iT邦大神 1 級 ‧ 2010-08-27 15:32:12 檢舉

不然還有更快的, 用 Apache 內建的 Re-write Engine 來重導向, 不用寫 php:
Using Apache's RewriteEngine to redirect requests to other URLS and to https://

你好,我改成30000port無法進入不知為什麼
用預設的443port可以,不知是否還有哪裡有可能呢?

至於http://it.com.tw這個網址,我直接從硬體防火牆那裡關80port了
所以使用者就一定要用https才能連入

Ray iT邦大神 1 級 ‧ 2010-08-27 16:50:51 檢舉

def123452002提到:
你好,我改成30000port無法進入不知為什麼
用預設的443port可以,不知是否還有哪裡有可能呢?

restart httpd 之後, 在 /var/log/httpd/error_log 裡面有沒有甚麼錯誤?

若在本機上用 telnet localhost:30000 進入, 可否成功連接? 或是被拒絕?

Ray iT邦大神 1 級 ‧ 2010-08-27 23:40:31 檢舉

raytracy提到:
telnet localhost:30000

Sorry, 我是說: telnet localhost 30000......老眼昏花的, 亂打一通....

你好,telnet 30000
很久都沒反應

打入quit停止,出現一些訊息

<pre class="c" name="code">Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
quit


<title>501 Method Not Implemented</title>

<h1>Method Not Implemented</h1>
<p>quit to / not supported.<br />
</p>

Connection closed by foreign host.

http 改成30000port重啟沒有錯誤

但是若telnet localhost 30000
error log有一些訊息

<pre class="c" name="code">[error] [client 127.0.0.1] Invalid method in request \xff\xf4\xff\xfd\x06quit
[Tue Aug 31 14:13:56 2010] [error] [client 127.0.0.1] Invalid method in request quit
Ray iT邦大神 1 級 ‧ 2010-08-31 15:20:32 檢舉

恩?.....有這個訊息, 就代表 httpd 已經成功的 Bind 到 30000 上去了;
現在要查, 為何他不回應您的瀏覽器....

用瀏覽器連上時, Log 內會有任何錯誤嗎? (包括 access_log 和 error_log)
瀏覽器這邊又會出現甚麼訊息?

用瀏覽器連上時,就是連很久沒反應,出現此網站無法使用之類的

access 的log

<pre class="c" name="code">127.0.0.1 - - [31/Aug/2010:14:04:53 +0800] "\xff\xf4\xff\xfd\x06quit" 501 211 "-" "-"
127.0.0.1 - - [31/Aug/2010:14:05:53 +0800] "quit" 501 206 "-" "-"
127.0.0.1 - - [31/Aug/2010:14:11:43 +0800] "\xff\xf4\xff\xfd\x06quit" 501 211 "-" "-"
127.0.0.1 - - [31/Aug/2010:14:13:56 +0800] "quit" 501 206 "-" "-"
127.0.0.1 - - [31/Aug/2010:14:17:31 +0800] "quit" 501 206 "-" "-"
127.0.0.1 - - [31/Aug/2010:14:33:26 +0800] "quit" 501 206 "-" "-"

error 的log

<pre class="c" name="code">
[Tue Aug 31 14:11:43 2010] [error] [client 127.0.0.1] Invalid method in request \xff\xf4\xff\xfd\x06quit
[Tue Aug 31 14:13:56 2010] [error] [client 127.0.0.1] Invalid method in request quit
[Tue Aug 31 14:17:31 2010] [error] [client 127.0.0.1] Invalid method in request quit
[Tue Aug 31 14:33:26 2010] [error] [client 127.0.0.1] Invalid method in request quit
[Tue Aug 31 14:35:53 2010] [notice] caught SIGTERM, shutting down
[Tue Aug 31 14:35:54 2010] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Aug 31 14:35:54 2010] [notice] Digest: generating secret for digest authentication ...
[Tue Aug 31 14:35:54 2010] [notice] Digest: done
[Tue Aug 31 14:35:54 2010] [notice] mod_python: Creating 4 session mutexes based on 10 max processes and 0 max threads.
[Tue Aug 31 14:35:54 2010] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations

大致上的iptables 的寫法

<pre class="c" name="code">iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j MASQUERADE
iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 192.168.1.17

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 30000 -j DNAT --to 192.168.1.17


iptables -N other
iptables -A other -m state --state ESTABLISHED,RELATED  -j ACCEPT
iptables -A other -p tcp --dport 30000 -m state --state NEW -i eth0 -j ACCEPT

還有另一個寫法
iptables -A INPUT -p tcp --dport 30000 -j ACCEPT

可是不管用哪種都不能成功使用 30000port

ssl_error log

<pre class="c" name="code">[Tue Aug 31 14:35:54 2010] [warn] RSA server certificate CommonName (CN) `localhost.localdomain' does NOT match server name!?
[Tue Aug 31 14:35:54 2010] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Tue Aug 31 14:35:54 2010] [warn] RSA server certificate CommonName (CN) `localhost.localdomain' does NOT match server name!?

ssl_access log

<pre class="c" name="code">74.85.88.45 - - [31/Aug/2010:14:36:22 +0800] "GET /webmail HTTP/1.1" 200 5809
74.85.88.45 - - [31/Aug/2010:14:36:23 +0800] "GET /data/openwebmail/images/sm_logo.png HTTP/1.1" 304 -
74.85.88.45 - - [31/Aug/2010:14:36:23 +0800] "GET /data/openwebmail/images/backgrounds/Globe.gif HTTP/1.1" 304 -
74.85.88.45 - - [31/Aug/2010:14:36:23 +0800] "GET /data/openwebmail/images/bg-titleblue.gif HTTP/1.1" 304 -

ssl_request log

<pre class="c" name="code">[31/Aug/2010:14:36:22 +0800] 74.85.88.45SSLv3 RC4-MD5 "GET /webmail HTTP/1.1" 5809
[31/Aug/2010:14:36:23 +0800] 74.85.88.45SSLv3 RC4-MD5 "GET /data/openwebmail/images/sm_logo.png HTTP/1.1" -
[31/Aug/2010:14:36:23 +0800] 74.85.88.45SSLv3 RC4-MD5 "GET /data/openwebmail/images/backgrounds/Globe.gif HTTP/1.1" -
[31/Aug/2010:14:36:23 +0800] 74.85.88.45SSLv3 RC4-MD5 "GET /data/openwebmail/images/bg-titleblue.gif HTTP/1.1" -
Ray iT邦大神 1 級 ‧ 2010-09-09 02:04:08 檢舉

# iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 192.168.1.17

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 30000 -j D...(恕刪)

看起來不像是 httpd 的問題, 請問為何要加上面這幾個 iptable? 若用 443 port 的話, 上面也會改成 443 嗎? 可否簡述一下你的網路架構?

Ray iT邦大神 1 級 ‧ 2010-09-09 02:05:21 檢舉

# iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 192.168.1.17

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 30000 -j DNAT --to 192.168.1.17

iptables -A other -p tcp --dport 30000 -m state --state NEW -i eth0 -j ACCEPT

看起來不像是 httpd 的問題, 請問為何要加上面這幾個 iptable? 若用 443 port 的話, 上面也會改成 443 嗎? 可否簡述一下你的網路架構?

上一面這二行是要設定為外部進來的ip都轉入為到虛擬的本地ip上面
本地ip出去也是,等於是做個nat的動作

是的我目前是用443port在做httpd
就寫為這樣
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to 192.168.1.17

自建的另一行other的
iptables -A other -p tcp --dport 443 -m state --state NEW -i eth0 -j ACCEPT

就是很奇怪的事,我這樣設443就可以,但是若改為 3xxxxx就不行

我的架構

外部->實体固ip->
->硬體防火牆(ip192.168.1.x),(發送192.168.1.17至mail主機)->
->mail server

不知這樣夠不夠清楚,若需要補充什麼,請您告知我會第一時間貼上來,

就是很奇怪的事,我這樣設443就可以,但是若改為 3xxxxx就不行

我的架構

外部->實体固ip->
->硬體防火牆(ip192.168.1.x),(發送192.168.1.17至mail主機)->
->mail server

不知這樣夠不夠清楚,若需要補充什麼,請您告知我會第一時間貼上來,

Ray iT邦大神 1 級 ‧ 2010-09-13 00:23:30 檢舉

你若直接用 https://192.168.1.17:30000 可以連得上嗎?

目前狀況是:

  1. 只有外部 IP 無法連上 port 30000?......還是,
  2. 內部和外部 IP 都無法連上 port 30000?

你好,時間所剩不多故,這個問題先結束,有空再試,443看起來還沒有明顯被攻擊的情況,倒是不知為何有人可以從外部連進來,然後發垃圾信

我只好把它ban掉,但是感覺不是長久之計,,我開個新問題,再請你看看是為什麼

我要發表回答

立即登入回答