一台VPS,已经装了军哥的lnmp,最近调试javaj,打算再装一个tomcat,但是希望能不通过端口访问而是使用同一个80端口,毕竟只有一个VPS,也方便管理,于是搜索并整理了写,如下:
1、环境 :centos、已有lnmp
2、目的:安装tomcat,并使tomcat项目与lnmp共用80端口
3、过程:
(1)centos上安装tomcat:
yum -y install tomcat

部署完tomcat项目后,项目访问地址默认为:http://1.1.1.1:8080
(2)配置nginx:
cd /usr/local/nginx/conf/vhost/
为区分,可分别创建java.conf php.conf:
各自内容如下:
php.conf
server
    {
        listen	80;
	server_name php.domain.com
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/default/mysite;
	include none.conf;
	include enable-php.conf;
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }
        location ~ /\.
        {
	allow all;
        }
        access_log off;
    }
javaj.conf
upstream java{
    server 127.0.0.1:8080 weight=1;
}
server {
       listen       80;
       server_name domain.com www.domain.com;  
        location / {
                        proxy_pass http://localhost:8080;  
                        proxy_pass_header Server;
                        proxy_set_header Host   $host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Scheme $scheme;
                        proxy_set_header Host $host;
                        proxy_set_header X-Forwarded-For $remote_addr;
            }
}
因为本身lnmp的nginx运行在80端口,如果在其他端口,则内容可再参考java.conf修改:
(3)修改后重启lnmp
lnmp restart
即可通过php.domain.com 访问tomcat项目,domain.com访问lnmp项目






![[八卦] 王婷婷—揭秘一个大三女生的性爱录像-微慑信息网-VulSee.com](http://free.86hy.com/crack/pic/1.jpg)
![[随笔]今天国际警察节-微慑信息网-VulSee.com](http://photo.sohu.com/20041017/Img222528326.jpg)

 青云网
