2.0 Nginx基本配置

cd /opt/nginx/conf/ #进入nginx配置文件目录

vim nginx.conf #编辑配置文件

1,基本配置介绍:

server {

listen 80;

server_name localhost;

location / {

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

多配置一个81端口

server {

listen 81;

server_name localhost;

location / {

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

 

cd ../sbin

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

http://192.168.227.4:81/

http://192.168.227.4

两个地址页面一样说明配置成功

2,配置端口转发

server {

listen 81;

server_name localhost;

location / {

proxy_pass http://www.baidu.com;

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

3,配置域名转发

server {

listen 81;

server_name test.baidu;

location / {

proxy_pass http://www.baidu.com;

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

server {

listen 81;

server_name test.163;

location / {

proxy_pass http://www.163.com;

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

测试注意:需要在hosts配置自己的域名映射

发布了179 篇原创文章 · 获赞 492 · 访问量 26万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 终极编程指南 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览