Facebook开发者社区
标题:
FB小游戏开发准备六(Nginx 开启SSL服务及跨域处理)
[打印本页]
作者:
破晓
时间:
2018-11-1 17:04
标题:
FB小游戏开发准备六(Nginx 开启SSL服务及跨域处理)
使用Let’s Encrypt的免费证书请参看之前帖子
准备工作
安装nginx:
第一步 – 添加Nginx存储库
要添加CentOS 7 EPEL仓库,请打开终端并使用以下命令:
yum install epel-release
复制代码
第二步 – 安装Nginx
现在Nginx存储库已经安装在您的服务器上,使用以下yum命令安装Nginx :
yum install nginx
复制代码
在对提示回答yes后,Nginx将在服务器上完成安装。
nginx 启动和停止:
systemctl start nginx
systemctl stop nginx
复制代码
如果想在系统启动时启用Nginx。请输入以下命令:
systemctl enable nginx
复制代码
配置SSL服务
第一步:
进入到 /usr/local/nginx/html
复制一个 crossdomain.xml 过去允许跨域访问
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
复制代码
第二步:配置SSL
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name _;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_certificate "/etc/letsencrypt/live/code2048.net/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/code2048.net/privkey.pem";
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /crossdomain.xml {
alias /usr/share/nginx/html/crossdomain.xml;
}
location / {
proxy_pass http://tomcat_game;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_request_headers on;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
复制代码
此处配置了代理,不需要可以无视
主要内容为:
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name _;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_certificate "/etc/letsencrypt/live/code2048.net/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/code2048.net/privkey.pem";
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
复制代码
fullchain.pem 和 privkey.pem 为申请的Let’s Encrypt的免费证书
也可以使用工具 转换成 crt 和 key 文件 转换工具:
https://github.com/Neilpang/acme ... -to-apachenginx-etc
启动服务
配置完成后启动服务
来源:
http://blog.airmyth.com/450.html
作者:
破晓
时间:
2018-11-1 17:12
Tomcat 跨域处理
创建全局过滤器:
CorssFilter.java
package com.airmyth.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
public class CorssFilter implements Filter {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
httpResponse.addHeader("Access-Control-Allow-Origin", "*");
httpResponse.setHeader("Access-Control-Allow-Headers", "*");
httpResponse.setHeader("Access-Control-Allow-Methods", "GET, PUT, DELETE, POST");
filterChain.doFilter(servletRequest, servletResponse);
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
复制代码
把这个打成jar包 放到 Tomcat 的 lib 文件夹下,然后修改 conf/web.xml
加入过滤器配置:
<filter>
<filter-name>corssFilter</filter-name>
<filter-class>com.airmyth.filter.CorssFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>corssFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
复制代码
然后重启 Tomcat
jar包见附件:
lib.rar
(1.21 KB, 下载次数: 1)
2018-11-1 17:12 上传
点击文件名下载附件
作者:
saladin
时间:
2018-11-13 15:09
Windows7系统的怎么弄?
作者:
破晓
时间:
2018-11-19 18:08
saladin 发表于 2018-11-13 15:09
Windows7系统的怎么弄?
windows没搞过哦
作者:
dhvlkaqdtblhkje
时间:
2018-12-17 13:23
强烈感谢楼主
欢迎光临 Facebook开发者社区 (http://bbs.zcsftek.com/)
Powered by Discuz! X3.2