突然需要用到jsp,因此在centos上做了一个综合的环境,很简单的配置,有些方面或多或少有点问题,但确实解决了我的问题。
nginx通过监听不同的端口将数据转发,这方面确实强。
我通过在虚拟机上加2块网卡,实现对不同ip的监听,不过用个本地域名似乎更容易些!
#安装tomcat
yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps
#安装httpd
yum install httpd
#修改httpd端口 改为81
vi /etc/httpd/conf/httpd.conf
#启动会出现Permission denied: make_sock: could not bind to address
#下面命令增加81非常规端口
semanage port -a -t http_port_t -p tcp 81
#下面命令安装semanage
yum install policycoreutils-python
#安装nginx
yum install nginx
#修改配置文件配置虚拟机
#修改下面的listen ip和server_name就可实现不同的转发
server {
listen 80;
listen 192.168.137.133:80;
server_name 192.168.137.133;
location / {
root /var/lib/tomcat6/webapps/;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host:80;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
}
server {
listen 80;
listen 192.168.137.132:80;
server_name 192.168.137.132;
location / {
root /var/www/html/;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host:80;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:81;
}
}
service nginx start
service httpd start
service tomcat6 start
http://127.0.0.1 #会看到nginx的默认页面
http://192.168.137.132 #会看到apache的默认页面
http://192.168.137.133 #会看到tomcat的默认页面
yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps
#安装httpd
yum install httpd
#修改httpd端口 改为81
vi /etc/httpd/conf/httpd.conf
#启动会出现Permission denied: make_sock: could not bind to address
#下面命令增加81非常规端口
semanage port -a -t http_port_t -p tcp 81
#下面命令安装semanage
yum install policycoreutils-python
#安装nginx
yum install nginx
#修改配置文件配置虚拟机
#修改下面的listen ip和server_name就可实现不同的转发
server {
listen 80;
listen 192.168.137.133:80;
server_name 192.168.137.133;
location / {
root /var/lib/tomcat6/webapps/;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host:80;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
}
server {
listen 80;
listen 192.168.137.132:80;
server_name 192.168.137.132;
location / {
root /var/www/html/;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host:80;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:81;
}
}
service nginx start
service httpd start
service tomcat6 start
http://127.0.0.1 #会看到nginx的默认页面
http://192.168.137.132 #会看到apache的默认页面
http://192.168.137.133 #会看到tomcat的默认页面
如果有问题还希望指出,还有,这个没有配置nginx的负载平衡,有需要的自己百度或谷歌!
当前还没有任何评论