2.0 Nginx基本配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011418530/article/details/87157005

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配置自己的域名映射

猜你喜欢

转载自blog.csdn.net/u011418530/article/details/87157005