當你獲得雲服務器之后,
你有這樣一個需求:當你要訪問一個url的時候,這個URL只能在人家的雲服務器上訪問(比如百度),所以你要買百度的BCC,你可能在想在BCC起服務,那樣有點麻煩,直接使用nginx代理就可以解決問題了,因為url涉及到驗證,所以要把請求頭帶上。
首先下載nginx
apt-get install nginx
最后配置nginx配置文件就可以啦!
配置文件一般在: /etc/nginx/sites-enabled/
快速查找配置文件:
命令:locate nginx.conf
配置文件內容如下:
server{
listen 80;
server_name xxxxxxxxxxx.com; # 你自己的域名
location / {
proxy_pass http://xxxxxxxxxx.com; # 在目標url
proxy_rediect off;
# 把你需要帶的請求頭都帶上
proxy_set_header Host $http_host;
proxy_set_header accept-encodeing 'gzip, deflate';
proxy_set_header content-type 'application/json';
proxy_set_header x-bce-date $http_x_bce_date; # 動態的值 請求頭就會帶過來
proxy_set_header authorization $http_authorization;
proxy_set_header accept '*/*';
}
}
重啟nginx:
sudo /etc/init.d/nginx reload
這樣 你直接訪問你的域名 實際上訪問的就是你的目標url了,驗證也在頭里面了。
如果驗證是放在url里那就沒這么麻煩了,不用配置哪些頭信息,把頭信息去掉,
location / {
proxy_pass http://xxxxxxxxxx.com; # 在目標url
proxy_rediect off;
}