nginx的项目实战:nginx反向代理微服务端口
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx的项目实战:nginx反向代理微服务端口相关的知识,希望对你有一定的参考价值。
参考技术A 一、nginx环境配置我这里就不详细说明了上章节有介绍,我这里就直接上正菜了,简单介绍下conf文件配置。cd /etc/nginx/conf.d
vim app.conf
upstream app #upstream 的命名必须区分
server 192.168.0.2:8088;
server 192.168.0.1:8088; #不做集群填写单个就行,最好为内网
server
listen 80;
listen 443 ssl;
client_max_body_size 50M;
client_body_buffer_size 30M;
server_name app.com; #域名
root /404;
#index index.html index.htm;
ssl_certificate /etc/nginx/cert/6093394_app.com.pem;
ssl_certificate_key /etc/nginx/cert/6093394_api.app.com.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;
access_log /opt/nginx-log/app.access.log main;
error_log /opt/nginx-log/app.error.log notice;
set $corsHost "";
if ($http_origin ~* "^https://a.com")
set $corsHost $http_origin; #跨域配置,比如当a.com
需要调用app.com
代理的接口必须配置,
可配置多个
location /
client_body_buffer_size 30M;
if ($request_method = 'OPTIONS')
add_header 'Access-Control-Allow-Origin' '$corsHost';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
return 204;
add_header 'Access-Control-Allow-Headers' 'origin, accept, authorization, if-match, if-unmodified-since, dnt, x-mx-reqtoken, keep-alive, user-agent, x-requested-with, cache-control, content-type,languagecode,F-Token';
proxy_next_upstream http_500 http_502 http_503 http_504 timeout error invalid_header;
proxy_pass http://app; #和upstream命名的必须一样
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
...
#的后面的提示需要认真看都是需要根据自己的配置进行修改的
以上是关于nginx的项目实战:nginx反向代理微服务端口的主要内容,如果未能解决你的问题,请参考以下文章
CentOS8.x上安装Nginx配置SSL证书反向代理域名到不同端口