nginx location 无效缘由

http 请求80端口html

https 请求443端口nginx

 

server虚拟机1web

  listen  10010;api

  listen 443 ssl;服务器

  server_name  域名1  域名2  域名3;websocket

  监听 域名1:10010  域名2:10010 域名3:10010 .........session

 

server虚拟机2socket

  listen  80;spa

  server_name  域名1  域名2  域名3;代理

  监听 域名1:80域名2:80域名3:80.........

 

server的 server_name:losten_port 决定惟一性

 

  若是请求为http:则被 server虚拟机2 代理,再依据uri 匹配  location 

 

举例:::

server { listen 443 ssl; server_name draymond7107.com; index index.html index.htm; ssl_certificate /usr/local/nginx/conf/cert/***.pem; ssl_certificate_key /usr/local/nginx/conf/cert/***.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 /websocket{ allow all; index index.html index.htm; proxy_pass http://localhost:10010; include proxy.conf; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection “Upgrade”; } location / { index index.html index.htm; proxy_pass http://draymond_api; //负载 include proxy.conf; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }

 

 

server { listen 80; server_name draymond.com draymond7107.com ;  //监听 域名为 draymond.com draymond7107.com 端口为 80 的请求(域名须要解析到本服务器的ip上(把www.baidu.com配到此处,请求百度首页也不会被代理)) index index.html index.htm; location / { index index.html index.htm; proxy_pass http://draymond_api;
 include proxy.conf; } location /nginx-status { stub_status on; access_log on; } error_page 500 502 503 504  /50x.html; location = /50x.html { root html; } }

 

同一个虚拟主机,配置的listen 不一样,则监听的端口也不一样(为何server_name能够重复的缘由)

  请求 

http://draymond7107.com/websocket 被虚拟机2(80端口) 代理,致使将请求转发到location / {}

https://draymond7107.com/websocket 被虚拟机1(443端口) 代理,请求转发到 location /websocket{}


转发路径

  虚拟主机:端口号 /location  

  当location不起做用的时候,排查下 请求的虚拟主机与端口号,,而后再排查具体转发到哪一个 location 了

相关文章
相关标签/搜索