1: nginx 是由C 编写,本身包含了一些库,首先需要安装gc++
sudo apt-get install build-essential
2:安装 pcre8.2
tar zxvf pcre-8.20.tar.gz
# cd pcre-8.20
# ./configure --prefix=/usr/local/pcre-8.20
3:安装nginx
# tar zxvf nginx-1.1.13.tar.gz
安装nginx前同时需要安装openssl 和libssl-dev
1:下载源码openssh-6.0p1.tar.gz 解压;
2:执行make 和 sudo make install命令
3:安装libssl:sudo apt-get install libssl-dev
# cd nginx-1.1.13 // 安装nginx --with-pcre --with-openssl就是上面的解压路径
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/guotonglin/nginx/pcre-8.35 --with-openssl=/home/guotonglin/nginx/openssh-6.0p1
4:启动nginx
(ubuntu需要用sudo) sudo /usr/local/nginx/sbin/nginx 启动ngxin
停止:sudo /usr/local/nginx/sbin/nginx -s stop
修改配置: nginx.conf
代码解析:
#gzip on;
server {
listen 80; //反向代理服务器监听的端口
server_name 192.168.15.129; //反向代理服务器IP
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://192.168.15.1:8080; // 通过代理的服务器(即幕后的真实服务器)
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
//至此反向代理服务器可以转发到一台服务器;
此处如果有多个服务器要做负载均衡:
则在 #gzip on; 和server 之间加入一下配置
upstream local_tomcat {
server 192.168.15.23:8080 weight=1; //反向代理服务器要代理的服务器集
server 192.168.15.24:8081 weight=5; //后面的weight值越大表示被访问的机会越大,可不写
}
将proxy_pass的值修改为:http://local_tomcat //此处的 local_tomcat 名字为上面定义的值;
//至此反向代理服务器可以转发到多台服务器 并实现负载均衡;
sudo apt-get install build-essential
2:安装 pcre8.2
tar zxvf pcre-8.20.tar.gz
# cd pcre-8.20
# ./configure --prefix=/usr/local/pcre-8.20
3:安装nginx
# tar zxvf nginx-1.1.13.tar.gz
安装nginx前同时需要安装openssl 和libssl-dev
1:下载源码openssh-6.0p1.tar.gz 解压;
2:执行make 和 sudo make install命令
3:安装libssl:sudo apt-get install libssl-dev
# cd nginx-1.1.13 // 安装nginx --with-pcre --with-openssl就是上面的解压路径
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/guotonglin/nginx/pcre-8.35 --with-openssl=/home/guotonglin/nginx/openssh-6.0p1
4:启动nginx
(ubuntu需要用sudo) sudo /usr/local/nginx/sbin/nginx 启动ngxin
停止:sudo /usr/local/nginx/sbin/nginx -s stop
修改配置: nginx.conf
代码解析:
#gzip on;
server {
listen 80; //反向代理服务器监听的端口
server_name 192.168.15.129; //反向代理服务器IP
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://192.168.15.1:8080; // 通过代理的服务器(即幕后的真实服务器)
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
//至此反向代理服务器可以转发到一台服务器;
此处如果有多个服务器要做负载均衡:
则在 #gzip on; 和server 之间加入一下配置
upstream local_tomcat {
server 192.168.15.23:8080 weight=1; //反向代理服务器要代理的服务器集
server 192.168.15.24:8081 weight=5; //后面的weight值越大表示被访问的机会越大,可不写
}
将proxy_pass的值修改为:http://local_tomcat //此处的 local_tomcat 名字为上面定义的值;
//至此反向代理服务器可以转发到多台服务器 并实现负载均衡;