1.nginx配置文件
1)上传证书文件到/usr/local/nginx/sslkey/
目录下,没有能够本人新建目录。
2)新建nginx.conf
,其配置如下:
user root;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; fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; 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; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 9; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php application/javascript application/json; gzip_disable "MSIE [1-6]\."; gzip_vary on; server { listen 80; server_name zomem.com; rewrite ^(.*) https://$server_name$1 permanent; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } server { listen 443 ssl http2; server_name zomem.com; ssl_certificate /usr/local/nginx/sslkey/zomem.com.pem; ssl_certificate_key /usr/local/nginx/sslkey/zomem.com.key; ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4'; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; add_header Strict-Transport-Security "max-age=31536000"; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; fastcgi_param HTTPS on; fastcgi_param HTTP_SCHEME https; location / { proxy_pass http://127.0.0.1:3080; } location /api/bidu/ { proxy_pass http://127.0.0.1:3000/; } } server { listen 80; server_name file.zomem.com; rewrite ^(.*) https://$server_name$1 permanent; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } server { listen 443 ssl http2; server_name file.zomem.com; ssl_certificate /usr/local/nginx/sslkey/file.zomem.com.pem; ssl_certificate_key /usr/local/nginx/sslkey/file.zomem.com.key; ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4'; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; add_header Strict-Transport-Security "max-age=31536000"; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; fastcgi_param HTTPS on; fastcgi_param HTTP_SCHEME https; location /bidu { proxy_pass http://127.0.0.1:6000/; } }}
其中,
ssl_certificate /usr/local/nginx/sslkey/zomem.com.pem;ssl_certificate_key /usr/local/nginx/sslkey/zomem.com.key;
是加载ssl证书文件的,门路就是之前上传的中央。
location /api/bidu/ { proxy_pass http://127.0.0.1:3000/;}
是api的地址,服务器对应端口3000
,申请地址为:https://zomem.com/api/bidu
。
location /bidu { proxy_pass http://127.0.0.1:6000/;}
是文件的地址,对应服务器端口6000
,文件地址为:https://file.zomem.com/bidu
。
编辑保留后,笼罩服务配置文件:/usr/local/nginx/conf/nginx.conf
,而后重启nginx。
2.启动服务器
批改server/.env
外面的STATIC_URL=https://file.zomem.com/bidu
,以及对应的数据库
账号密码等配置,而后将后盾我的项目server
里的内容,上传到服务器/root/bidu/server
外面,再npm install
。
启动服务器后盾运行:
cd ~/bidu/serverpm2 start ./bin/www --name biduApi
启动图片服务器:
pm2 serve static 6000 --name biduImg --spa# 在文件目录static下,启动一个6000端口的服务
这样,cdn的地址https://file.zomem.com/bidu
,就会通过nginx转发到本地6000端口的地址了,即static目录。
验证cdn是否胜利:间接输出图片地址到浏览器,如https://file.zomem.com/bidu/articles/1.jpg
,查看network,如果图片的ip不是服务器ip,阐明是用的cdn的ip。如果显示HIT,则是cdn胜利了,如果MISS则是失败。
这个时候,在小程序的app.js配置里,换一下对应的接口和图片地址,就能够应用了,之后就是上传审核,而后上线。没想像的那么难吧~哈哈~
/* 更换线上地址 *//*config: { api: 'http://localhost:3000', file: 'http://localhost:3000',}*/config: { api: 'https://zomem.com/api/bidu', file: 'https://file.zomem.com/bidu',}
3.零碎防火墙问题
如果你在阿里云的后盾,开启了80,443端口,还是不能拜访,很大可能是centos的零碎防火墙没开启这两个端口,可能进行如下操作排查:
查看防火墙状态
firewall-cmd --state
进行firewall
systemctl stop firewalld.service//长期敞开防火墙,重启后会从新主动关上systemctl restart firewalld//查看防火墙状态firewall-cmd --statefirewall-cmd --list-all//Disable firewallsystemctl disable firewalldsystemctl stop firewalldsystemctl status firewalld//Enable firewallsystemctl enable firewalldsystemctl start firewalldsystemctl status firewalld
禁止firewall开机启动
systemctl disable firewalld.service
开启端口(白名单)
firewall-cmd --zone=public --add-port=80/tcp --permanent命令含意:--zone #作用域--add-port=80/tcp #增加端口,格局为:端口/通信协定--permanent #永恒失效,没有此参数重启后生效
删除白名单
firewall-cmd --permanent --zone=public --remove-port=80/tcp
重启防火墙
firewall-cmd --reload
查新的防火墙规定
firewall-cmd --list-all
demo地址