经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » Android » 查看文章
写给Android开发的Nginx入门
来源:cnblogs  作者:yupenglei  时间:2021/6/15 8:55:35  对本文有异议

介绍

  1. 高性能的web服务器,开源免费
  2. 一般用于做静态服务,负载均衡
  3. 用于反向代理 

安装

Mac使用homeBrow安装,Centos使用yum安装

常用命令

  1. # 重启nginx
  2. nginx -s reload
  3. # 停止nginx
  4. nginx -s stop
  5. # 测试配置文件是否正确,同时会列出配置文件位置
  6. nginx -t

Nginx配置

  1. # 使用 nginx -t 来显示conf文件位置
  2. http{
  3. server{
  4. listen 8080; # 监听端口
  5. server_name localhost; # _相当于0.0.0.0;也可以指定域名
  6. # 配置静态文件
  7. location / {
  8. root /User/me/html; # /路由寻找的目录
  9. index index.html; # index文件名
  10. }
  11. # 配置动态转发
  12. location /home { # 转发
  13. proxy_pass http://localhost:8001;
  14. }
  15. location /api/ { # 转发
  16. proxy_pass http://localhost:8000;
  17. proxy_set_header Host $host;
  18. }
  19. }
  20. }

快速启动动态服务

用途:
  1. 和前端联调时,登录功能依赖cookie,必须使用浏览器联调
  2. cookie跨域不共享,前端和server必须同域
  3. 需要用nignx做代理,让前后端同域 

使用node的http服务

  1. # 需要sudo权限;-g是global全局安装
  2. npm install http-server -g
  3. # 启动http服务,指定端口,默认是8080
  4. http-server -p 8001

云服务器配置https

  1. 申请腾讯云证书
  2. 下载并上传到服务器,解压:目录中有Apache、Nginx、Tomcat等文件夹,使用Nginx文件夹中的两个文件,crt文件是证书,key文件是秘钥
  3. 配置conf:conf文件里有http部分和https部分,默认是打开http部分的,现在注释掉http部分,打开https部分,并指定crt和key文件以及域名即可
  4. 浏览器访问https://<host> 即可 
  1. server {
  2. listen 443 ssl http2 default_server;
  3. listen [::]:443 ssl http2 default_server;
  4. server_name xxx.xx yyy.yy; # 指定申请的域名,若多个域名使用空格隔开
  5. root /usr/share/nginx/html;
  6.  
  7. ssl_certificate "/etc/pki/nginx/server.crt”; # 复制crt文件
  8. ssl_certificate_key "/etc/pki/nginx/private/server.key”; # 复制key文件
  9. ssl_session_cache shared:SSL:1m;
  10. ssl_session_timeout 10m;
  11. ssl_ciphers PROFILE=SYSTEM;
  12. ssl_prefer_server_ciphers on;
  13.  
  14. # Load configuration files for the default server block.
  15. include /etc/nginx/default.d/*.conf;
  16.  
  17. location / {
  18. }
  19.  
  20. error_page 404 /404.html;
  21. location = /40x.html {
  22. }
  23.  
  24. error_page 500 502 503 504 /50x.html;
  25. location = /50x.html {
  26. }
  27. }

  

原文链接:http://www.cnblogs.com/yudaxia/p/14855608.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号