linux服务器同时开启tomcat和nginx冲突问题
解决方法:nginx使用默认80端口监听(宝塔界面可改),tomcat使用8080端口(tomcat目录/conf/server.xml)
/www/server/panel/vhost/nginx/创建tomcat.conf文件,加入以下内容
server {
listen 80;
server_name *.kemiyo.top;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://x.x.x.x:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}}
打开nginx.conf文件,最后默认有引入include /www/server/panel/vhost/nginx/*.conf;
只需在server部分加入
location / {
proxy_pass http://xx.xx.xxx.xxx:8080; (加上这个,指定自己本机的tomcat的地址)
root html;
index index.html index.htm;
}
重启tomcat-》》重启nginx,不重启nginx也行
tip:更改tomcat端口前应先
ps -ef |grep tomcat
kill pid -9 (pid:对应进程id)
注意服务器和宝塔的端口放行