nginx的conf文件,两种配置方式,第一种无ssl证书,第二种有ssl证书。
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了nginx的conf文件,两种配置方式,第一种无ssl证书,第二种有ssl证书。,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2452字,纯文字阅读大概需要4分钟。
内容图文
以下为无ssl证书配置的请求转发
server { listen 80; server_name api.******.com; location ~* /union { client_max_body_size 3000m; proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-PORT $remote_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; proxy_redirect default; proxy_connect_timeout 3000; if ($http_origin ~ https://(.*).******.com){ set $allow_url $http_origin; } if ($request_method = OPTIONS) { add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS, HEAD"; # add_header Access-Control-Allow-Origin $allow_url; add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers "Cookie,Set-Cookie,Origin,X-Requested-With,token,authorization,Accept,Content-type"; add_header Access-Control-Allow-Credentials "true"; add_header Content-Type "text/plain; charset=utf-8"; add_header Content-Length 0; return 204; } } }
以下为有ssl请求转发
将以下代码替换成自己的证书路径:
ssl_certificate /etc/nginx/cert/api.pem;
ssl_certificate_key /etc/nginx/cert/api.key;
server { listen 80; server_name api.******.com; rewrite ^(.*)$ https://${server_name}$1 permanent; } server { listen 443; server_name api.******.com; ssl on; ssl_certificate /etc/nginx/cert/api.pem; ssl_certificate_key /etc/nginx/cert/api.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location ~* /union { client_max_body_size 3000m; proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-PORT $remote_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; proxy_redirect default; proxy_connect_timeout 3000; if ($request_method = OPTIONS) { add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS, HEAD"; add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers "Cookie,Set-Cookie,Origin,X-Requested-With,token,authorization,Accept,Content-type"; add_header Access-Control-Allow-Credentials "true"; add_header Content-Type "text/plain; charset=utf-8"; add_header Content-Length 0; return 204; } } }
原文:https://www.cnblogs.com/hahahehexixihoho/p/10797657.html
内容总结
以上是互联网集市为您收集整理的nginx的conf文件,两种配置方式,第一种无ssl证书,第二种有ssl证书。全部内容,希望文章能够帮你解决nginx的conf文件,两种配置方式,第一种无ssl证书,第二种有ssl证书。所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。