300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > nginx https 根据应用不同的标识转发到不同的服务器端口

nginx https 根据应用不同的标识转发到不同的服务器端口

时间:2020-10-27 23:10:58

相关推荐

nginx https 根据应用不同的标识转发到不同的服务器端口

一、背景

https只支持433端口。

其它端口的应用得在url中传一个应用标识参数,然后nginx根据这个参数转发到对应的端口

比如需要将

https://39.106.4.0/kubesys/

转发到

http://39.106.4.0:30308/kubesys/

二、修改配置文件nginx.conf

其位置一般在/usr/local/nginx/conf/

增加下面几行代码即可

location /kubesys/ {set $target_url "http://39.106.4.0:30308$request_uri";proxy_pass $target_url;}

完整代码如下

#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;#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 logs/access.log main;sendfile on;#tcp_nopushon;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;rewrite ^(.*)$ https://39.106.4.0$1 permanent;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server#server {listen 443 ssl;server_name localhost;ssl_certificate/usr/local/nginx/conf/39_106_4_0.pem;ssl_certificate_key /usr/local/nginx/conf/39..key;ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;location /kubesys/ {set $target_url "http://39.106.4.0:30308$request_uri";# return 502 "hah $target_url haha";proxy_pass $target_url;}location / {proxy_pass http://39.106.4.0:9537;}}}

三、加载配置文件

cd /usr/local/nginx/sbin# 停止./nginx -s stop# 启动./nginx

四、通过浏览器测试是否成功

nginx中 $1,$2,$3是什么?

/cbmljs/article/details/86573248

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。