笔者只对外开放了一个ip端口,但实际使用不止一个端口,那么需要把ip端口映射出来。这里使用Nginx来映射ip端口。比如将前端系统的ip端口映射出去了,还需要后台的ip端口,这样前后端才能结合使用
-
通过后台服务名(dwiot-cloud)来分发到后台服务ip端口,这样可以直接通过外网访问后台服务。通过已开放的ip端口+dwiot-cloud就相当于在访问219:8088/dwiot-cloud一样
-
第二个location是为前端页面配置的,将前端页面打包放在html下的dwiot-web(自创的目录)下,这样默认192.168.5.219:80就是在访问dwiot-web下的前端界面(上截图所示)文章来源:https://www.toymoban.com/news/detail-512121.html
-
完整配置:文章来源地址https://www.toymoban.com/news/detail-512121.html
#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_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name 192.168.5.219; #后台服务配置,配置了这个location便可以通过http://域名/dwiot-cloud/xxxx 访问 location ^~ /dwiot-cloud { proxy_pass http://192.168.5.219:8088/dwiot-cloud/; proxy_set_header Host 192.168.5.219; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题 location / { root html/dwiot-web; index index.html index.htm; if (!-e $request_filename) { rewrite ^(.*)$ /index.html?s=$1 last; break; } } } # another virtual host using mix of IP-, name-, and port-based configuration # server { listen 8000; # listen somename:8080; server_name 192.168.5.219; location /web-prototype { root html/web-prototype; index index.html index.htm; } } # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
到了这里,关于nginx 映射ip端口服务的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!