worker_processes 1;
events {
worker_connections 1024;
}
http{
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 165;
log_format main 'host=$host|$http_x_forwarded_for|$http_x_real_ip|remote_addr=$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
upstream uuuuu{
#远程服务器端口是80,就省略端口
server xxxx.xxx.com(你的域名或IP):端口 max_fails=10 fail_timeout=300s weight=1;
#server 127.0.0.1:8901 weight=1;
}
server {
# nginx 对外暴漏的端口
listen 80;
server_name xxxx.xxx.com(你的域名或IP);#服务接口在哪里,这个就写那个接口所在的服务器域名或IP
access_log logs/host.access.log main;
location / {
proxy_pass http://uuuuu/;
default_type application/json;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
if ($request_method = 'OPTIONS') {
return 204;
}
client_max_body_size 500m;
proxy_http_version 1.1;
proxy_connect_timeout 980;
proxy_read_timeout 800;
proxy_send_timeout 800;
proxy_redirect off;
proxy_set_header Host $server_name;# 远程是域名的时候最好使用server_name
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Content-Type 'application/json; charset=utf-8';
}
}
}