当前位置:   article > 正文

Nginx代理网站

nginx代理网站

a.我在tomcat下部署了一个javaweb项目,tomcat安装的服务器IP为:10.224.102.102,部署的项目在tomcat下的访问地址为:http://10.224.102.102:8080/dubbo-admin/

  b.我在IP为10.224.102.101的服务器下面安装成功了Nginx。

  c.那怎么样将tomcat下部署的网站使用Nginx代理呢?,修改Nginx的配置文件,修改命令:vim /usr/local/nginx/conf/nginx.conf

 

a.我在tomcat下部署了一个javaweb项目,tomcat安装的服务器IP为:10.224.102.102,部署的项目在tomcat下的访问地址为:http://10.224.1021.102:8080/dubbo-admin/

 

  b.我在IP为10.224.102.101的服务器下面安装成功了Nginx。

 

  c.那怎么样将tomcat下部署的网站使用Nginx代理呢?,修改Nginx的配置文件,修改命令:vim /usr/local/nginx/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;

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

    #配置tomcat的IP地址和访问端口
    upstream gw{
       server 10.224.102.102:8080 weight=1;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #Nginx代理服务设置
        location /dubbo-admin {
            proxy_pass http://gw/dubbo-admin;
        }

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

d.当配置完Nginx.conf之后,关闭文件,执行命令检查配置的文件是否有问题,如果如图所示则说明没有问题,否则需要检查配置是否出现问题



e.检查如果返回ok,则说明修改文件没有出现任何错误,这时候重启Nginx,命令为: /usr/local/nginx/sbin/nginx -s reload

会报如下错误:

解决:

nginx -c /usr/local/nginx/conf/nginx.conf

nginx -s reload

 

f.最后访问代理后的网站,http://10.224.102.101/dubbo-admin,如图所示:则说明已经代理访问:


 
 
 
 

 

参考:http://www.cnblogs.com/hanyinglong/p/5102141.html系列教程

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/996510
推荐阅读
相关标签
  

闽ICP备14008679号