第二十一周实践操作

一、配置nginx反向代理,实现api.x.com域名代理本地9001端口

安装nginx,并配置api.x.com主页
yum install -y nginx
cd /var/www/html
mkdir api.x.com
echo "api.x.com" > api.x.com/index.htm
# 编辑nginx的配置文件按照下列添加配置即可
vim /etc/nginx/conf/nginx.conf
# 在http{}段中添加以下内容
   server {
        listen 80;
        server_name api.x.com;

        location / {
            proxy_pass http://127.0.0.1:9001/;
        }
   }

   server {
        listen 9001;
        server_name 127.0.0.1;

        location / {
            root /var/www/html/api.x.com;
            index index.html;
        }
   }
配置hosts,使其测试能够通过域名访问
echo "127.0.0.1 api.x.com" >> /etc/hosts

nginx -t      # 测试配置文件是否有问题
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful

nginx -s reload   #重新加载nginx配置文件

curl http://api.x.com    #可以看到反向代理成功了
api.x.com
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。