Nginx专题:Nginx安装后常用功能配置

【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】

**开源地址:https://docs.qq.com/doc/DSmxTbFJ1cmN1R2dB **

mkdir extra

  • 利用server模块创建www和bbs两个虚拟站点

[root@nginx-01 conf]# cat -n nginx.conf

[root@nginx-01 conf]# sed -n ‘10,20p’ nginx.conf

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;

}

  • www站点

[root@nginx-01 conf]# cat extra/www.conf

server {

listen 80;

server_name www.yygg.com;

location / {

root html/www;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

  • bbs站点

[root@nginx-01 conf]# cat extra/bbs.conf

server {

listen 80;

server_name bbs.yygg.com;

location / {

root html/bbs;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html/bbs;

}

}

  • 主配置文件配置(nginx.conf)

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

include extra/www.conf;

include extra/bbs.conf;

}

  • 检查配置

[root@nginx-01 conf]# /app/nginx/sbin/nginx -t

nginx: the configuration file /app/nginx-1.18.0//conf/nginx.conf syntax is ok

nginx: configuration file /app/nginx-1.18.0//conf/nginx.conf test is successful

  • 创建站点目录

[root@nginx-01 conf]# mkdir /app/nginx/html/{www,bbs}

[root@nginx-01 conf]# echo “http://www.yygg.com” >>/app/nginx/html/www/index.html

[root@nginx-01 conf]# echo “http://bbs.yygg.com” >>/app/nginx/html/bbs/index.html

[root@nginx-01 conf]# echo “192.168.1.5 www.yygg.com bbs.yygg.com” >>/etc/hosts

  • 启动服务并测试

[root@nginx-01 conf]# /app/nginx/sbin/nginx

[root@nginx-01 conf]# curl www.yygg.com

http://www.yygg.com

[root@nginx-01 conf]# curl bbs.yygg.com

http://bbs.yygg.com

2.虚拟主机别名设置


以www站点为例,设置别名

所谓别名就是除了主域名外额外设置一个或多个域名

  • www.yygg.com设置别名yygg.com

[root@nginx-01 conf]# cat extra/www.conf

server {

listen 80;

server_name www.yygg.com yygg.com;

location / {

root html/www;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html/www;

}

}

  • 重启nginx测试

[root@nginx-01 conf]# /app/nginx/sbin/nginx -s reload

[root@nginx-01 conf]# cat /etc/hosts

192.168.1.5 www.yygg.com bbs.yygg.com yygg.com

[root@nginx-01 conf]# curl yygg.com

http://www.yygg.com

3.Nginx status状态信息配置


状态信息记录使用的是ngx_http_stub_status_module模块实现

  • 输入/app/nginx/sbin/nginx -V检查编译是否有上述模块:

nginx version: nginx/1.18.0

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)

built with OpenSSL 1.0.2k-fips 26 Jan 2017

TLS SNI support enabled

configure arguments: --user=nginx --group=nginx --prefix=/app/nginx-1.18.0/ --with-http_stub_status_module --with-http_ssl_module

  • 创建一个status的虚拟主机,方式参考标题1,status.conf配置文件如下:

server {

listen 80;

server_name status.yygg.com;

location / {

stub_status on;

access_log off;

}

}

  • 主配置文件nginx.conf追加status虚拟主机配置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值