发表于: 2019-12-23 20:55:10

2 1237


啥也不说就是干!!!

今天完成的事情:

1、关于tomcat 乱码

昨天部署至 tomcat服务器发现接口中文乱码,解决方案如下:

1)对于 post 请求,可以在 web.xml 中配置过滤器:

<filter>
   <filter-name>characterEncodingFilter</filter-name>
   <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
   <init-param>
       <param-name>encoding</param-name>
       <param-value>UTF-8</param-value>
   </init-param>
   <init-param>
       <param-name>forceEncoding</param-name>
       <param-value>true</param-value>
   </init-param>
</filter>
<filter-mapping>
   <filter-name>characterEncodingFilter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

2)对于 get 请求,在 tomcat 的 server.xml 配置文件中配置:

<Connector port="8080" protocol="HTTP/1.1"
          connectionTimeout="20000"
          redirectPort="8443" />

添加URIEncoding="utf-8"
<Connector port="8080" protocol="HTTP/1.1"
          connectionTimeout="20000"
          redirectPort="8443" URIEncoding="utf-8"/>

2、Nginx 配置

安装配置 Nginx:https://blog.csdn.net/t8116189520/article/details/81909574

Nginx 正常启动

将项目所在的 tomcat 服务器配置到 Nginx 中

1)nginx.conf

upstream tomcat {
   server 127.0.0.1:8088;
}

server {
    listen 80;
    server_name f0t1.top;
    location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://tomcat;
  }
}

2) 配置项目首页及tomcat contextPath

web.xml 中配置欢迎页

<welcome-file-list>
   <welcome-file>jsp/index.jsp</welcome-file>
   <welcome-file>index.html</welcome-file>
   <welcome-file>index.htm</welcome-file>
   <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

在欢迎页中请求 StudentController 的 student/ 方法

<html>
<body>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=student/">
</body>
</html>
<body>

接下来在 Tomcat 的 server.xml 中配置 Context Path

<Host name="localhost"  appBase="webapps"
     unpackWARs="true" autoDeploy="true">
   <Context docBase="JnshuTask2" path="/"  reloadable="true"  ></Context> /* Root Context */
   <Context docBase="ROOT" path="/admin"  reloadable="true" ></Context>            /* path 须为空 或 以/开头且不以/结束 */
</Host>

重启 Nginx 

项目访问正常

明天计划的事情:

项目二的深度思考部分
遇到的问题:

暂无
收获:

初步掌握了 Nginx 配置


返回列表 返回列表
评论

    分享到