Nginx 端口转发配置文件

来自一搜便知
跳到导航 跳到搜索

最终实现的效果:访问 https://abc.test.com:9000/api 就是访问:http://127.0.0.1:50001

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
 

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
 
	 
    server {
        listen 9000 ssl; 
        server_name  abc.test.com:9000;
        index index.php index.html index.htm default.php default.htm default.html;
        root         /usr/share/nginx/www;
	ssl_certificate "/usr/share/nginx/cert/abc.test.com.pem";
	ssl_certificate_key "/usr/share/nginx/cert/abc.test.com.key";
	ssl_session_timeout  10m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:laNULL:MD5:!ADH:!RC4;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
	proxy_redirect http:// $scheme://;
	port_in_redirect on;
	
	location ^~ /api {
			proxy_pass http://127.0.0.1:5001/api;
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		}
    } 
}