Linux Tomcat 80端口 Port 80 required by Tomcat v8.5 Server at localhost is already in use.

Port 80 required by Tomcat v8.5 Server at localhost is already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s).

因为装上了ubuntu,就在eclipse上设置tomcat端口为80,但是就显示说已被占用,不过我电脑才刚装上ubuntu,正常应该是没有其他程序被占用,然后在*上发现的一个解答就是说linux不开放1024以下的端口给非root用户。

上网找了好多解答,我感觉还是用nginx比较靠谱,毕竟以后应该会用nginx比较多,所以我就用nginx解决了。

利用nginx把80端口的转发到8080(我在tomcat上设置的1024以上的端口)。

nginx在ubuntu上安装的简单方法,也可以用其他方法安装,随习惯

sudo apt-get install nginx

我的nginx的配置文件在/etc/nginx/nginx.conf,因为配置文件默认include了/etc/nginx/sites-available/default,这个default就是初始的nginx配置文件,里面设置了当前nginx的默认端口,也就是80,当然也可以修改为其他的。

我就在default文件里的server里,修改了location为

        location / {
 44                 # First attempt to serve request as file, then
 45                 # as directory, then fall back to displaying a 404.
 46                 # try_files $uri $uri/ =404;
 47                 proxy_pass http://localhost:8080;
 49                 index index;
 50                 root /;
 51         }

然后就保存,在命令行里输入sudo nginx -s reload

没有显示错误就代表对了,然后我就启动tomcat,在地址栏输入了localhost,成功跳转了tomcat的项目里了。