1、YUM安装
参考 http://www.cnblogs.com/wutengbiao/p/4188986.html
2、gcc g++开发类库安装
yum install gcc gcc-c++
3、make编译环境安装
yum -y install gcc automake autoconf libtool make
4、安装PCRE库
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
./configure
make
make install
5、安装zlib库
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
6、安装openssl
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
cd openssl-1.0.1t
./config
make
make install
7、安装nginx
cd /usr/local/src
wget http://nginx.org/download/nginx-1.1.10.tar.gz
tar -zxvf nginx-1.1.10.tar.gz
cd nginx-1.1.10
./configure
make
make install
8、编辑配置文件
nginx解压路径下的conf文件,/usr/local/nginx/conf/nginx.conf
(1)修改域名为 hello.yanan.com
(2)配置tomcatIP端口 10.10.10.10:8080
(3)配置访问路径为 域名加后缀 /index.jsp
server {
listen 80;
server_name hello.yanan.com *. hello.yanan.com;
rewrite_log on;
if ($host ~ ^(.*)\. hello.yanan.com){
set $user $1;
}
location = / {
rewrite ^ /index.jsp;
}
location ~* (.*)\.(gif|jpg|jpeg|png|css|js|ico)$ {
proxy_pass http://10.10.10.10:8080/$1.$2;
}
location / {
rewrite ^(.*)$ $1?user=$user break;
proxy_pass http://10.10.10.10:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
9、配置本地host文件
在hosts文件(C:\Windows\System32\drivers\etc\hostsni)中配置IP、域名
10.10.10.10 hello.yanan.com
10、启动tomcat及nginx
浏览器中输入地址即可。如:hello.yanan.com
nginx启动服务
[root@test ~]# cd /usr/local/nginx/sbin
[root@test sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Nginx服务启动报错解决方法
11、Nginx停止服务
[root@test ~]# ps -axu | grep nginx
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 4675 0.0 0.0 103308 828 pts/0 R+ 13:20 0:00 grep nginx
root 25476 0.0 0.0 19732 612 ? Ss Aug04 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 24784 0.0 0.0 20148 1676 ? S Aug04 0:05 nginx: worker process
[root@test ~]# kill -TERM 25476
12、Nginx关闭服务
[root@test ~]# kill -9 25476
13、Nginx重启服务
[root@test ~]# cd /usr/local/nginx/sbin
[root@test sbin]#./nginx -s reload