首先安装nginx,参加博客:https://www.cnblogs.com/qfb620/p/5508468.html

按照博客写的访问127.0.0.1查看是否访问成功,成功即安装成功。

下一步就是配置127.0.0.1与域名scc.company.com的映射(也就是访问scc.company.com可以请求到本地指定端口的地址。我的项目在本地的8083端口,配置正确,就能访问到我的项目)

首先,通过switch hosts来添加本地对应域名的映射 127.0.0.1 sct.company.com

下一步,打开nginx.conf

找到server,配置如下

  server {
        listen       80;
        server_name  sct.company.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
           index  index.html index.htm;
        }
	   
        location /custom-web/ {
        proxy_pass   http://127.0.0.1:8083;
        }

主要改了下面两个地方

       server_name  sct.company.com;
        location /custom-web/ {
        proxy_pass   http://127.0.0.1:8083;
        }

好了,127.0.0.1对应域名sct.company.com配好了

记得重启nginx,进入到nginx的目录,

输入

nginx -s reload

进行重启。

没有报错就是重启成功

然后清空浏览器缓存,我是清空了好几次,

又ping了一下sct.company.com,看请求的是不是本地,

可以看到请求的是本地

这个时候,浏览器输入sct.company.com/custom-web/...访问一下项目地址 ,可以看到可以请求到tomcat上面的项目了

=================================分割线=========================================

下面看下重定向,配置如下

  server {
        listen       80;
        server_name  sct.lvmama.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #location / {
           # root   html;
           # index  index.html index.htm;
       # }
	   
	   location / {
	    rewrite ^/(.*)$ http://www.baidu.com/; 
	    proxy_pass   http://10.200.4.120:80;
	   }
	   
        location /customization-back-web/ {
        proxy_pass   http://127.0.0.1:8083;
        }

主要是这个代码:

  location / {
        rewrite ^/(.*)$ http://www.baidu.com/; 
        proxy_pass   http://10.200.4.120:80;
       }

nginx -s reload重启nginx 

你输入sct.company.com就会跳转到百度


       

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐