网站首页 > 技术教程 正文
一、多站点配置的引入
文件/etc/nginx/nginx.conf 中引入文件夹/etc/nginx/conf.d中的站点配置文件。
引入的代码为:
include /etc/nginx/conf.d/*.conf;
二、nginx的配置文件
1、查看nginx进程
systemctl status nginx
2、做语法检测,检测你修改的配置是不是存在问题
nginx -t
3、查看nginx所用的端口
netstat -anlpt | grep nginx
4、修改nginx的默认端口
vi /etc/nginx/conf.d/default.conf
5、查看进程pid
ps aux | grep nginx
6、pid文件(每个以.pid结尾的文件里面都有一个pid,每个文件对应一个应用)
/var/run
7、查看nginx的pid
/var/run/nginx.pid
8、多站点配置文件放置的位置
文件/etc/nginx/nginx.conf 中引入文件夹/etc/nginx/conf.d中的站点配置文件。
引入的代码为:
include /etc/nginx/conf.d/*.conf;
9、查看nginx的日志文件
more /var/log/nginx/error.log
10、修改nginx配置文件后的操作
10.1、检测配置是否正确
nginx -t
10.2、重启nginx服务
systemctl reload nginx
11、查看端口
netstat -anlpt | grep nginx
三、nginx 文件结构
1、结构如下:
... #全局块
events { #events块
...}
http #http块{
... #http全局块
server #server块
{
... #server全局块
location [PATTERN] #location块
{
...
}
location [PATTERN]
{
...
}
}
server
{
...
}
... #http全局块}
2、配置文件结构说明:
1、全局块:配置影响nginx全局的指令。一般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process数等。
2、events块(Main配置段,是核心配置段):配置影响nginx服务器或与用户的网络连接。有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。
Events {
#配置事件的
}
3、http块(标准http配置段,可选http配置段,都在http{}这里配置,每一种都是一个独立的):可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。
4、server块:配置虚拟主机的相关参数,一个http中可以有多个server。
5、location块:配置请求的路由,以及各种页面的处理情况。
注意:每一个配置参数都需要以分号结尾
三、多站点的配置
1、在文件/etc/nginx/conf.d中创建对应的配置文件,文件的名字可以任意取,但为了便于记忆和便于理解可以把文件名配置成相关的域名
2、有多少个站点就配置多少个配置文件
3、配置文件详细代码
server {
listen 80;#端口
server_name localhost;#域名
#charset koi8-r;//字符集
#access_log /var/log/nginx/host.access.log main;#日志
#url匹配
location / {#网站的配置,这里的斜杠代表是在下面html文件夹下
# location /hello {#网站的配置,这里的 /hello 代表是在下面html文件夹下的hello
root /usr/share/nginx/html; #这里代表的是网站的目录 网站的路径就等于你当前设置的目录下面的url
index index.html index.htm; #默认的首页
}
#error_page 404 /404.html; #找不到页面的时候显示的页面
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
- 上一篇: Nginx服务优化之日志切割与设置链接超时
- 下一篇: 《Nginx为什么快到根本停不下来?》
猜你喜欢
- 2024-10-09 程序员都应该懂的微服务容错与隔离:熔断保护、超时与重试原理
- 2024-10-09 Nginx为什么快到根本停不下来?(nginx解决什么问题)
- 2024-10-09 Nginx代理webSocket经常中断的解决方案,如何保持长连接
- 2024-09-09 怎么测试nginx反向代理(nginx反向代理配置参数)
- 2024-09-09 关于LNMP+Frp内网穿透环境下一个PHP程序运行超时的问题
- 2024-09-09 Nginx反向代理(nginx是干嘛用的)
- 2024-09-09 Nginx这么香,还不知道怎么学?看完这份Nginx笔记你能立马上手
- 2024-09-09 「每天一道面试题」Nginx 502错误原因和解决方法
- 2024-09-09 年轻人你不讲武德,Nginx之负载均衡演示
- 2024-09-09 应用程序加固Nginx篇(如何给应用加固)
你 发表评论:
欢迎- 最近发表
-
- Win11学院:如何在Windows 11上使用WSL安装Ubuntu
- linux移植(Linux移植freemodbus)
- 独家解读:Win10预览版9879为何无法识别硬盘
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- Docker镜像瘦身(docker 减小镜像大小)
- 在linux上安装ollama(linux安装locale)
- 渗透测试系统Kali推出Docker镜像(kali linux渗透测试技术详解pdf)
- Linux环境中部署Harbor私有镜像仓库
- linux之间传文件命令之Rsync傻瓜式教程
- 解决ollama在linux中安装或升级时,通过国内镜像缩短安装时长
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)