首页 > 其他 > 详细

nginx 入门配置

时间:2015-06-05 19:28:44      阅读:220      评论:0      收藏:0      [点我收藏+]

这个星期公司的定期分享内容是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

 

nginx 入门配置

原文:http://www.cnblogs.com/yingbing/p/4555267.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!