1. 程式人生 > >linux https代理squid搭建

linux https代理squid搭建

如何在linux上用squid搭建代理伺服器_足夠詳細 在linux上用squid搭建代理伺服器,這個東東全世界都是,但是有一些細節問題在網上說的不明不白的,折騰了半天搞好了,如鯁在喉不吐不快。 一臺電腦linux系統,上不了網,於是在另外一臺可以上網的linux上面搭建一個代理伺服器,步驟如下: 下載:squid-3.2.9.tar.bz2 上傳到伺服器後解壓: 解壓: tar -vxjf squid-3.2.9.tar.bz2 解壓後生成目錄:squid-3.2.9 進入目錄翻看文件INSTALL: xxxx> more INSTALL  To build and install the Squid Cache, type:         % ./configure --prefix=/usr/local/squid         % make all         % make install To run a Cache, you will need to:         1. customize the squid.conf configuration file:               % vi /usr/local/squid/etc/squid.conf         2. Initalise the cache:               % /usr/local/squid/sbin/squid -z         3. start the cache:               % /usr/local/squid/sbin/squid If you want to use the WWW interface to the Cache Manager, copy the cachemgr.cgi program into your httpd server's cgi-bin directory. 安裝步驟: ./configure --prefix=/usr/local/squid
make all sudo make install(因為要拷貝到系統目錄,需要root許可權,所以sudo了,你也可以root登入執行,我是ubuntu的系統,所以用sudo,有root許可權就行) 檢查配置檔案: sudo vi /usr/local/squid/etc/squid.conf 配置項1: # Squid normally listens to port 3128 http_port 3128 配置項2: acl localnet src 192.168.0.0/16 http_access allow localnet 配置項3: # Uncomment and adjust the following to add a disk cache directory. cache_dir ufs /usr/local/squid/var/cache/squid 100 16 128 cache_mem 32 MB (這一條必須配置) 否則你就會遭遇報錯: 2013/10/12 16:16:55 kid1| WARNING cache_mem is larger than total disk cache space! 安裝好了以後,系統中新建了一個使用者squid,在組中一查,發現屬於nobody組的: cat /etc/passwd|grep squid cat /etc/group|grep 65534 安裝squid的所在目錄是:/usr/local/squid 我閒得沒事幹,直接改了所屬使用者為squid:nobody sudo chown -Rf squid:nobody /usr/local/squid 建立cache的時候,對下面目錄需要nobody使用者許可權,這個是網上沒有說的很清楚的地方,折騰了我半天: sudo chown -Rf nobody /usr/local/squid/var/cache/ sudo chown -Rf nobody /usr/local/squid/var/logs/ 否則你會遭遇: WARNING: Cannot write log file: /usr/local/squid/var/logs/cache.log FATAL: Failed to make swap directory /usr/local/squid/var/cache/squid/00: (13) Permission denied 初始化squid.conf裡配置的cache目錄,就是建立了一堆的目錄: sudo /usr/local/squid/sbin/squid -z 在前臺啟動squid,並輸出啟動過程  sudo /usr/local/squid/sbin/squid -N -d1 顯示ready to server reques,則啟動成功。可以鍵入ctrl+c,停止squid,並以後臺執行的方式啟動。  我沒有在配置檔案中配置DNS,而是在 /etc/resolv.conf 中配置: domain site nameserver x.x.x.x 所以打印出來的日誌中就這樣的: 2013/10/12 16:42:13| Adding nameserver x.x.x.x from /etc/resolv.conf squid從這個配置檔案中讀取了dns配置來用。 啟動squid後臺執行  sudo /usr/local/squid/sbin/squid -s 檢查一下程序是否存在:ps -ef|grep squid 通過squid客戶端檢視squid執行狀態  /usr/local/squid/bin/squidclient -h 127.0.0.1 -p 3128 mgr:info 那臺不能上網的機器配置如下: export http_proxy=http://192.168.199.235:3128/ 可以把這句寫到你的啟動檔案中,比如什麼.profile或者.bashrc,或者/etc/profile等等。 取消:unset http_proxy 測試一下能不能上網了: wget www.163.com