nginx服务器访问前端及其它服务器nacos配置实例
其中 /home/kw360/cloud/dev 为前端文件路径。10.0.0.148:8083为JAVA应用地址和端口,10.0.0.148:8848为nacos管理地址和端口
user root;
#cpu核数
worker_processes 2;
#警告日志
error_log /home/kw360/logs/nginx_error.log warn;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#关闭访问日志
access_log off;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
#gzip on;
# include /home/kw360/app/nginx/conf/conf.d/*.conf;
upstream consumer
{
server 10.0.0.148:8083;
ip_hash;
}
upstream nacosManager
{
server 10.0.0.148:8848;
ip_hash;
}
server {
listen 80;
#listen 443 ssl;
server_name localhost;
#ssl_certificate /data/cloud/https_cert/dev.kw360.cn.pem;
#ssl_certificate_key /data/cloud/https_cert/dev.kw360.cn.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 / {
root /home/kw360/cloud/dev;
index index.html index.htm index.php;
try_files $uri $uri/ /index.html;
}
location /web {
proxy_pass http://consumer;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Origin "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 5m;
}
}
server {
listen 8001;
server_name localhost;
location / {
proxy_pass http://nacosManager/nacos/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Origin "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 5m;
}
}
}