nginx 1.4.7
tomcat7 8080(访问端口为8090)
tomcat7 8090(访问端口为8090)
目标:当我在浏览器输入 localhost之后,页面显示 hello 8080 或者 hello 8090
反复刷新, 有时出现8080,有时出现8090
具体操作:
1 准备测试软件如图:
2 编写显示文件
a编写apache-tomcat-7.0.52_8080的index.jsp内如如下:
<html>
<head></head>
<body>hello word 8080</body>
</html>
b 将apache-tomcat-7.0.52_8080\webapps\ROOT/index.jsp 修改为 index.jspx(备份index.jsp)
c 将编写的index.jsp 复制到 apache-tomcat-7.0.52_8080\webapps\ROOT/ 目录
8090 操作同上,将显示的内容改成 hello 8090 就可以了
3 修改8090 server.xml的端口(保证2台tomcat不冲突,正常启动)
4 启动tomcat 分别在浏览器输入地址:
A localhost;8080 显示如图:
B localhost:8090显示如图:
5 配置nginx.conf如图:
A 新添加一个8888端口的监听, 映射到a.com上面
B 在server上面添加 a.com响应的服务器,
6 启动nginx 在终端输入命令:start nginx, 然后在浏览器输入:
localhost:8888出现如图:
附件:完整的nginx.conf如下====================================================:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream a.com{
server localhost:8080;
server localhost:8090;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
listen 8888;
server_name a.com;
location / {
root html;
index index.html index.htm;
proxy_pass http://a.com;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}