1:新建tomcat下的项目。取名就叫tomcat。访问http://127.0.0.1:8080/tomcat/ 看到This is my JSP page。
2:下载nginx。解压得到 nginx-1.9.9 配置nginx-1.9.9\conf下的nginx.conf文件
http:下加
upstream localhost {
server localhost:8080;
}
server下加
location / {
proxy_pass http://localhost;
}
一个最终的nginx.conf是
==
==
#user nobody;
#cpu的核心数
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#用来配置nginx中所有处理连接的设置
events {
#默认最大的并发数是1024
worker_connections 1024;
}
#配置nginx的http请求
http {
#mime.types是外部的一个文件,包含了很多静态文件
include mime.types;
#设置文件使用的默认mime type application/octet-stream代表二进制传输
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;
#nginx模块一般被分成三大类:handler、filter和upstream
upstream localhost {
server localhost:8080;
}
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
#在一个http中可以启动多个server,而在一个server中,可以有多个location配置
location / {
proxy_pass http://localhost;
}
#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;
#}
}
# 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 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
==
==
>>cd nginx-1.9.9
>>start nginx.exe
访问 http://127.0.0.1/ 看到nginx主页,nginx端口默认80.
访问 http://127.0.0.1/tomcat/ 看到上面tomcat的页面。