nginx 配置多域名共享 80 端口
#默认 nobody
#user nobody;
#工作进程个数,一般跟服务器cpu核数相等,或者N-1
worker_processes 2;
pid logs/nginx.pid;
# 单个进程最大连接数
events {
worker_connections 1024;
}
http {
# sendfile使用高效文件传输,提升传输性能。启用后才能使用tcp_nopush,是指当数据表累积一定大小后才发送,提高了效率。
sendfile on;
# tcp_nopush 与 tcp_nodelay 互斥
tcp_nopush on;
# keepalive_timeout设置客户端与服务端请求的超时时间,保证客户端多次请求的时候不会重复建立新的连接,节约资源损耗。
keepalive_timeout 65;
# gzip启用压缩,html/js/css压缩后传输会更快
gzip on;
default_type application/octet-stream;
include mime.types;
include /usr/local/nginx/conf/vhosts/example.conf;
# 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;
# }
#}
}
example.conf
# 图片资源服务器
server {
listen 80;
server_name image.project.example.com;
location / {
root /opt/upload/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# tomcat
server {
listen 80;
server_name project.example.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://project.example.com:8010;
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}