Dec 10
删除Apache2
$ sudo service apache2 stop
$ sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
$ sudo apt-get autoremove
$ whereis apache2
$ sudo rm -rf /etc/apache2
安装nginx
apt-get install build-essential git gcc g++ make
wget "http://nginx.org/download/nginx-1.7.8.tar.gz"
wget "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz"
wget "https://www.openssl.org/source/openssl-1.0.1j.tar.gz"
wget "http://zlib.net/zlib-1.2.8.tar.gz"
git clone https://github.com/cuber/ngx_http_google_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
tar xzvf nginx-1.7.8.tar.gz
tar xzvf pcre-8.38.tar.gz
tar xzvf openssl-1.0.1j.tar.gz
tar xzvf zlib-1.2.8.tar.gz
cd nginx-1.7.8
./configure \
--prefix=/usr/local/nginx \
--with-pcre=../pcre-8.38 \
--with-openssl=../openssl-1.0.1j \
--with-zlib=../zlib-1.2.8 \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_spdy_module \
--with-http_gzip_static_module \
--with-ipv6 \
--with-http_sub_module \
--add-module=../ngx_http_google_filter_module \
--add-module=../ngx_http_substitutions_filter_module
make
make install
配置nginx
server {
server_name scholar.google.com;
resolver 8.8.8.8;
location / {
proxy_pass https://scholar.google.com;
}
}
重启nginx:
/usr/local/nginx/sbin/nginx -s reload
报错代码:
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)
解决方法:
1.重新运行一下:
/usr/local/nginx/sbin/nginx
2.重启nginx:
/usr/local/nginx/sbin/nginx -s reload
3.运行:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Oct 04
1.下载需要的文件
# cd ~
# git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
2.查看之前Nginx编译configure
# nginx -V
nginx version: nginx/1.2.7
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with- http_ssl_module --with-http_gzip_static_module --with-ipv6
3.重新编译Nginx
# cd ~/lnmp1.1-full/
# vim upgrade_nginx.sh
# 大概在配置文件的line 90左右,重新configure
# 添加--with-http_sub_module --add-module=/root/ngx_http_substitutions_filter_module
# ./configure --prefix= --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --add-module=/root/ngx_http_substitutions_filter_module
4.修改Nginx配置文件并重启
# /etc/init.d/nginx -t
# 提示没有错误的话可以执行重启
# /etc/init.d/nginx restart
# 或者执行以下两步
# /etc/init.d/nginx stop
# /etc/init.d/nginx start
转自:http://rmingwang.com/install-nginx-third-modules-http_sub_module.html
Oct 20
转自:https://gist.github.com/2686973
# /etc/nginx/sites-available/blog.shellexy.info
server {
resolver 8.8.8.8;
listen 80;
server_name blog.shellexy.info;
#access_log off;
access_log /var/log/nginx/blog.shellexy.info.access.log;
location / {
#避免远方启用压缩导致无法替换纯文本
proxy_set_header Accept-Encoding "";
#按需替换为您的 blogger
proxy_pass $scheme://shellexy.wordpress.com$request_uri;
sub_filter http://shellexy.wordpress.com http://blog.shellexy.info;
#替换全文所有文本
sub_filter_once off;
}
}
Jul 07
前几天弄了一个免费的VPS来玩,128M的基本的配置,用来安装其他的软件由于优化不会,可能不能很好的运行,正好有一个博客是建在OpenShift上的,可以用Nginx来做一下反向代理,我Ping了一下,速度不是很快,仅限于可以访问,在配置完成后在电脑上实际测试,速度还是可以的,有总比没有强的。
现在VPS上用apt-get安装Nginx,然后在下载源文件进行编译安装,这样做的好处是在编译的时候不用指定某些路径,实际上我就不会指定路径,路径不对的话很容易造成在系统里不能正常启动。安装上面的方法相当于将原有的安装文件稍稍更新了一下而已。具体步骤如下:
1.下载zlib
wget http://zlib.net/zlib-1.2.7.tar.gz
tar -zxvf zlib-1.2.7.tar.gz
2.下载pcre
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
tar -zxvf pcre-8.30.tar.gz
3.下载nginx
wget http://nginx.org/download/nginx-1.2.2.tar.gz
tar -zxvf nginx-1.2.2.tar.gz
4.安装nginx
cd nginx-1.2.2
./configure --with-http_sub_module --with-pcre=../pcre-8.30 --with-zlib=../zlib-1.2.7
make
make install
5.配置nginx.conf
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
client_header_buffer_size 64k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 32 16k;
proxy_busy_buffers_size 64k;
server {
listen 94.249.183.187:80; ## listen for ipv4
#listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name rh.chunchu.org;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Accept-Encoding "";
proxy_pass http://redhat.chunchu.org;
sub_filter redhat.chunchu.org rh.chunchu.org;
sub_filter_once off;
proxy_redirect off;
}
}
用vi打开/etc/nginx/文件夹的下文件nginx.conf,在http代码后面输入上述代码后保存推出。
6.重启nginx
以root身份输入命令:
/etc/init.d/nginx restart
7.另附Google GHS反向代理的配置文件
在nginx.conf文件中添加代码:
upstream ghs {
ip_hash;
server ghs.google.com;
server 72.14.203.121;
server 72.14.207.121;
server 74.125.43.121;
server 74.125.47.121;
server 74.125.53.121;
server 74.125.77.121;
server 74.125.93.121;
server 74.125.95.121;
server 74.125.113.121;
server 216.239.32.21;
server 216.239.34.21;
server 216.239.36.21;
server 216.239.38.21;
}
server {
listen 94.249.243.220:80; ## listen for ipv4
#listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name ghs.chunchu.org;
location / {
proxy_redirect off;
#proxy_set_header Host $host;
proxy_pass http://ghs;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
然后重启nginx即可。
8.注意事项
(1).新安装nginx后,启动nginx一般是不成功的,因为Apache将80端口占用了,须将占用80端口的进程全部Kill,然后再启动nginx就行了。
(2).在编译nginx时,不要忘记添加–with-http_sub_module参数,因为添加这个参数时,反向代理的网站的主页是正常的,但是点击链接后会跳转到原网站的地址,添加–with-http_sub_module参数,然后按照上述示例修改就可以解决这个问题。
(3).我曾试图将网页的反向代理和Google GHS的反向代理合二为一,但是实践了一次都不能成功,都只能是其中的一种成功,二者不能并存,不知奥是我设置的问题还是二者根本就不能同时使用。
(4).在添加proxy_pass http://redhat.chunchu.org;时,如果网址后面没有“/”则表示是相对链接,有”/”则表示是绝对链接,这个有时候也会出现问题。另外要仔细检查配置文件,不要丢失了最后的分号“;”。
Recent Comments