最近帮朋友做了两个网站,预算很小很小.小到两个网站只能跑在一台512M内存的公网服务器上(tomcat+mysql,由于内存太小了,只能把两个网站部署在同一个tomcat上),每个网站有自己的域名,初步考虑使有nginx做反向代理,把两个域名映射到相应的应用上。因此就有了标题所说的“nginx多域名单服务器单IP单Tomcat不同应用”上的配置问题。Nginx介绍的废话就不多说了,在这里把配置文件贴出来给大家参考一下吧:
域名A:www.a.com的配置文件如下:
- server {
- listen 80;
- server_name *.a.com;
- location / {
- proxy_pass http://localhost:8080/projectA/;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- }
- server {
- listen 80;
- server_name *.b.com;
- location / {
- proxy_pass http://localhost:8080/projectB/;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- }