Centos 7.x 搭建 nginx 反向代理--单服务器

nginx的搭建已经在前面一篇文章写过,具体详见

Centos 7.x 搭建 nginx-1.1.19

Centos 7.x 搭建tomcat

1、首先需要将tomcat 搭建好,请参考文章 Centos 7.x 搭建tomcat

2、进入到nginx的安装目录,修改nginx的配置文件,注意一点: 此时的安装目录是/usr/local/nginx,并不是我们当时执行make 的解压路径,请读者牢记,我们make install 执行完毕后就会默认的将我们的nginx安装到/usr/local/nginx目录

[root@jinhus ~ ]# cd  /usr/local/nginx/conf/
[root@jinhus conf]# vi nginx.conf

打开配置文件,修改反向代理的端口号

 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://127.0.0.1:8080;
            index  index.html index.htm;
        }

3、在server里面,location 下添加proxy_pass 服务器IP:8080,我这边使用的本机,即proxy_pass http://127.0.0.1:8080;

保存配置文件,启动nginx 

4、在未配置反向代理时,访问服务器ip:80端口号时,默认会访问nginx的测试界面,如下

5、配置完反向代理后,访问同样的ip和端口号,将会访问配置的界面,我们这边是将80端口代理到tomcat的8080 端口,如图所示

猜你喜欢

转载自blog.csdn.net/weixin_38638777/article/details/103945253