Linux上 Nginx + Tomcat部署war(简单)

来源:互联网 发布:重庆时时彩数据分析 编辑:程序博客网 时间:2024/05/17 07:02

Linux上 Nginx + Tomcat部署war

安装tomcat

  1. 下载apache-tomcat-8.5.11-windows-x64.zip并解压

  2. 修改tomcat-user.xml增加以下内容:

    <role name="manager-gui" /><user username="tomcat" password="tomcat" roles="manager-gui" />
  3. 如果需要远程访问,还需要修改${tomcat_home}/webapps/manager/META-INF/context.xml,修改里面允许的ip地址正则,比如我们允许192开头的登陆

    <Context antiResourceLocking="false" privileged="true" >    <Valve className="org.apache.catalina.valves.RemoteAddrValve"     allow="192\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /></Context>
  4. 直接放war包到${tomcat_home}/webapps/目录下,或者通过先启动tomcat再通过页面部署war包

  5. 启动tomcat

    ${tomcat_home}/bin/startup.sh

安装nginx

最好安装pcre,否则在location配置正则的时候会报错

  1. 下载pcre并解压
  2. ./configure && make && make install
  3. 下载nginx并解压
  4. 进入目录执行命令:

    ./coonfigure --prefix=/etc/nginx --with-http_stub_status_module

    可能提示configure不成功,需要添加–without,如果不需要提示的模块,可以添加到命令尾部。

  5. make && make install

  6. 配置nginx.
    进入/etc/nginx/conf目录,编辑nginx.conf文件:

    ...#针对server,最简单的配置server {    listen 80;    server_name 192.168.1.2;    location / {        proxy_pass  http://192.168.1.2:8080;    } //将所有访问请求转发给tomcat进行处理...
  7. 验证配置文件.

    /etc/nginx/sbin/nginx -t#如果没有问题输出#the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok#the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
  8. 启动nginx.

    /etc/nginx/sbin/nginx #使用ps -ef|grep nginx查看进程是否正确启动。有一个master线程,然后若干worker线程。
  9. 访问http://192.168.1.2成功看到应用即代表配置成功。

  10. 停止nginx.

    /etc/nginx/sbin/nginx -s stop

总结:

  1. nginx 可以作为web服务器的反向代理,将request和response缓存(组成完成的请求再发给web server),另外可以缓存静态资源,不必一直去web server获取,配置负载均衡,从而提高web server的处理能力和响应速度。
  2. 遇到了403的问题。
    • 定义了server的root,但是index指向的index.html index.jsp等内容不存在会报403.(没有尝试成功)
    • 对工程目录没权限。chmod -R 755 xxxx
0 0
原创粉丝点击