首页 新闻 赞助 找找看

nginx配置文件如何访问tomcat主页,我试了半天弄不出来

0
悬赏园豆:10 [已解决问题] 解决于 2017-05-31 16:37

#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;

    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;
        #}
    }


    # 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;
    #    }
    #}

}

 

求解

skateweb的主页 skateweb | 初学一级 | 园豆:170
提问于:2017-05-31 15:27
< >
分享
最佳答案
0

1.将127.0.0.1 映射到local.server.com

2.配置文件主要如下:

http {

 

  # 实现负载均衡
  upstream dis{
      server 192.168.0.108:8080 weight=1;  # 另一台局域网内服务器
      server 127.0.0.1:8080 weight=1;  # 本台服务器
  }
  server{
      listen 9090;
      server_name local.server.com;
      location / {
           proxy_pass http://dis;
      }

  }

}

3. 访问local.server.com:9090 即可映射到配置的两台服务器。 权重为1:1

收获园豆:5
MalcolmFeng | 初学一级 |园豆:2 | 2017-05-31 16:09

有点没看懂 我应该改哪里呢 大神

skateweb | 园豆:170 (初学一级) | 2017-05-31 16:11

@skateweb: 

如果是windows,打开系统目录:c:/windows/system32/drivers/etc找到hosts文件,打开hosts文件并在最后面新添加一条记录 例如:127.0.0.1 local.server.com 

如果是mac,http://www.cnblogs.com/malcolmfeng/p/6816119.html。

MalcolmFeng | 园豆:2 (初学一级) | 2017-05-31 16:15

@Mal

按着你说的加上了  不过 就第一次访问 0.4秒 之后刷新  就又会慢了 又要等好久 我试过好几次,没回在性的网页输入网址就很快 只要一刷新就很慢求解

colmF: 

skateweb | 园豆:170 (初学一级) | 2017-05-31 16:22

@MalcolmF: 在地址栏点击回车刷新 第一次 很慢,我连着点击两次 就又很快了 咋回事啊

skateweb | 园豆:170 (初学一级) | 2017-05-31 16:24

@skateweb: 分配到这两台服务器的 比重是 1:1  。 可能是分配到某一台的时候有问题。 你要确定两台都可以正常访问。

MalcolmFeng | 园豆:2 (初学一级) | 2017-05-31 16:25

@MalcolmF: 我现在在公司自己电脑做测试,那个有问题擦。杂看啊 。可不可以就先用我的电脑来做访问啊,先不用两个服务器呢。求解,有方法吗?

skateweb | 园豆:170 (初学一级) | 2017-05-31 16:28

@skateweb: 可以再装个linux

MalcolmFeng | 园豆:2 (初学一级) | 2017-05-31 16:31

@MalcolmF: 没别的办法吗 老大

skateweb | 园豆:170 (初学一级) | 2017-05-31 16:33
其他回答(1)
1

http://www.cnblogs.com/lbblog/p/5551400.html

收获园豆:5
[3] | 园豆:1174 (小虾三级) | 2017-05-31 15:42

为啥我访问 tomcat 速度非常慢啊 超级慢 求解 大神

支持(0) 反对(0) skateweb | 园豆:170 (初学一级) | 2017-05-31 15:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册