使用nginx发布网站

来源:互联网 发布:jackson转换json 编辑:程序博客网 时间:2024/05/20 11:52

原文地址:http://www.cnblogs.com/da2jie/archive/2013/01/07/1667200.html

在公司要在自己的服务器上发布网站时遇到一个这样的情况

公司网站是外包公司制作的,用的是ASP

公司服务中心网站是JSP做的

公司购买的邮件服务器的webmail是PHP的

公司两台服务器一台是数据库服务器一台最为上述三个网站的web服务器,web服务器通过路由器NAT到因特网提供服务器.

 

现在的问题是:

1.做JSP的技术人员很娴熟的使用tomcat发布JSP,但是还不知道如何使用Apache发布ASP和PHP

2.用IIS发布ASP和PHP很容易实现,但是IIS不能发布JSP

由于这两个问题使得我们以前采用的方法是:

1.使用IIS开着80端口,Tomcat使用8888端口;

2.IIS主要发布公司网站,配置PHP支持后建立/mail虚拟目录发布邮件webmail,建立/zhongxin 虚拟目录转发到8888端口显示服务中心的网站

这样的确能够实现,但是始终有个8888感觉很不爽~

效果如下(域名仅仅举个例子):

通过浏览器打开 www.test.com 进入公司网站

打开 www.test.com/mail 进入mail

输入 www.test.com/zhongxin 后会自动跳转到 www.test.com:8888

这样的效果确实不能让我们满意

 

因为这个不满意我突然留意到了nginx,写了一大堆,终于到主角了

有关nginx的介绍自己去Google, 小心你知道得太多了!

我在其官方网站上下载了0.7.65版,进入conf目录用记事本打开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;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

 
   }

}

在我这个例子里面,其他地方不用改,直接关注红色部分

server {
        listen       80;   #监听80端口
        server_name  localhost; #主机名/域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {           #配置本地web目录 *
            root   html;
            index  index.html index.htm;
        }

}

nginx本身就是一个web服务器,但是我没有用它来发布网页 因此本地的web服务我就不要了,根据我的需求我做了如下更改

首先将IIS停掉,端口改为81,tomcat的端口确认为8888,且通过127.0.0.1:8888/zhongxin/ 也能访问到服务中心网站的首页

然后修改nginx.conf文件的内容

server {
        listen       80;   #监听80端口
        server_name  www.test.com; #主机名/域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {           #配置本地web目录 *
            proxy_pass http://192.168.0.3:81;  #将请求转发到81端口 
        }

       location /zhongxin/ {

           proxy_pass http://192.168.0.3:8888;  #将请求转发到8888端口   
       }

}

完成这个简单的修改后,运行nginx.exe,如果没有错误网站就启动了,可以通过浏览器测试访问了

 

这仅仅是nginx功能的其中一项,我是来不及研究太多就先这样临时搞出来了~

身在小公司就是好,什么都能用到,什么都能学到~~


0 0
原创粉丝点击