Blog 第二天

做了什么

  • nginx+tomcat 组合

    nginx+tomcat 组合

    配置 nginx

  1. 安装
     yum install -y nginx
    
  2. 运行
     service nginx start
    
  3. 修改配置文件

     vi /etc/nginx/nginx.conf
    

    http 部分如下配置

     http {
     access_log off;
     error_log /var/log/nginx/error.log crit;
     sendfile            on;
     keepalive_timeout   30;
     gzip on;
     gzip_disable "MSIE [1-6]\.";
     gzip_vary on;
     gzip_proxied any;
     gzip_comp_level 4;
     gzip_min_length 1024;
     gzip_http_version 1.1;
     gzip_types text/plain application/x-javascript application/json text/xml text/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/bmp;
     open_file_cache max=655350 inactive=20s;
     open_file_cache_valid 30s;
     open_file_cache_min_uses 2;
    
     include             /etc/nginx/mime.types;
     default_type        application/octet-stream;
    
     include /etc/nginx/conf.d/*.conf;
     upstream backend {
     #tomcat端口
     server localhost:18080;[](http://)
     }
     server {
         listen       80;
         listen       443;        
         include /etc/nginx/default.d/*.conf;
         ssl on;
         #证书配置
         ssl_certificate "/etc/nginx/xxx.crt";
         ssl_certificate_key "/etc/nginx/xxx.key";
    
         location ~ \.(html|js|css|gif|jpg|png|bmp|swf) {
         expires 30d;
         root /usr/local/tomcat/webapps/ROOT;
         }
         location ^~ / {
         proxy_pass http://backend$request_uri;
         proxy_set_header  Host $host:$server_port;
         proxy_set_header  X-Real-IP  $remote_addr;
         client_max_body_size  10m;
         }
         error_page 404 /404.html;
             location = /40x.html {
         }
    
         error_page 500 502 503 504 /50x.html;
             location = /50x.html {
         }
     }
     }
    

    配置 Tomcat

  4. 修改配置文件
     vi /usr/local/tomcat/conf/server.xml
    
    修改端口为 18080
     <Connector port="18080" protocol="HTTP/1.1"
                connectionTimeout="20000"
                redirectPort="8443"/>
    
  5. 关闭 nginx+Tomcat
     service tomcat stop
     service nginx stop
    
  6. 检查端口占用
     lsof -i tcp:80 #80为端口
     #如有占用 记录PID
     kill -9 PID
    
  7. 启动 nginx+Tomcat
     service tomcat start
     service nginx start