标签:
这个星期公司的定期分享内容是Nginx,于是就要写作业了。
一、动静分离
1、下载Windows 版本的Nginx,解压,放到C盘下。进入目录,然后按然shift键右键,打开命令行,输入:
start nginx
2、访问localhost,启动成功。

3、然后做如下配置:

4、启动tomcat,访问localhost:8080:

5、重启nginx:
nginx -s reload
6、访问localhost/index.jsp,静态文件全部找不到,页面跑版。

7、把tomcat的静态文件放到目录下, 再次访问localhost/index.jsp:

8、一个简单的动静分享就做完啦。
二、绑定多个域名
1、在配置文件和server同级的位置加上这一句
include C:/nginx-1.9.1/conf/vhosts/*.conf;
2、在conf目录下新建一个vhosts文件夹,里面新建两个文件:
tomcat.conf
server {
listen 80;
server_name tomcat.ice.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://localhost:8080;
}
#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;
#}
}
star.conf
server {
listen 80;
server_name star.ice.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root "H:/repository/svn/4";
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;
#}
}
3、在host文件中加下以下代码:
127.0.0.1 star.ice.com 127.0.0.1 tomcat.ice.com
4、重启nginx
nginx -s reload
5、分别访问star.ice.com和tomcat.ice.com:


6、打完收工,关闭nginx:
nginx -s quit
标签:
原文地址:http://www.cnblogs.com/yingbing/p/4555267.html