server {
listen 443 ssl;
listen [::]:443 ssl;
include snippets/ssl.conf;
include snippets/ssl-params.conf;
server_name id24.com www.id24.com;
location / {
proxy_pass http://localhost:9090;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
listen [::]:80;
server_name id24.com www.id24.com;
return 302 https://$server_name$request_uri;
}
转发所有来自域名id24.com的请求到本地的9090端口
EG:
#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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name 10cpu.cn;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
client_max_body_size 300m;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_pass http://127.0.0.1:55555;
}
}
server {
listen 80;
server_name localhost;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
client_max_body_size 300m;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_pass http://127.0.0.1:8080;
}
}
}
纠正一个之前的错误。。。是可以配置多个对80的监听方案的,本身并不会冲突。。会逐个匹配。。这里就是配置的根据域名转发,域名进来的转发到55555gateway,localhost进来的直接访问8080
例子3
一级域名作为网页访问使用
二级域名api作为应用服务使用
server{
listen 80;
server_name 10cp.cn;
location / {
proxy_pass http://47.113.67.238:19527;
}
}
server{
listen 80;
server_name api.10cp.cn;
location / {
proxy_pass http://47.113.67.238:10080;
}
}
负载均衡
# 配置可用均衡服务器
upstream OrdinaryPolling {
server 47.243.67.238:10081;
server 47.243.67.238:10080;
}
server{
listen 80;
server_name api.10cpu.cn;
location / {
client_max_body_size 300m;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_http_version 1.1;
proxy_pass http://OrdinaryPolling; 代理时使用配置的负载均衡
}
# 外层websockets 升级
location /websocket/ {
client_max_body_size 300m;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "upgrade";
proxy_pass http://47.243.67.238:10081;
}
}