写点什么

Nginx 核心配置文件介绍,rabbitmq 面试题

作者:MySQL神话
  • 2021 年 11 月 27 日
  • 本文字数:1403 字

    阅读完需:约 5 分钟

proxy_read_timeout 600;


client_body_timeout 2m;


main 段



用于设置 master 进程启动后,fork 出的 worker 进程运行在哪个用户和用户组下

#user nobody;

指定工作衍生进程数(一般等于 CPU 的总核数或总核数的两倍,两个四个 CPU,就设置 8)

worker_processes 1;

指定错误日志存放的路基,错误日志记录级别可选 [debug | info | notice | warn | error | crit ]

#error_log logs/error.log;


#error_log logs/error.log notice;


#error_log logs/error.log info;

指定 pid 存放的路径

#pid logs/nginx.pid;

指定文件描述符数量

worker_rlimit_nofile 512000;


events 段




events {

使用的网络 I/O 模型,Linux 推荐使用 epoll 模式 FreeBSD 推荐使用 kqueue 模型

use epoll;

单个 woker 进程支持的最大连接数

worker_connections 1024;


}


http 段




http {


include mime.types;


default_type application/octet-stream;


#log_format main 'remote_user [request" '

'body_bytes_sent "$http_referer" '

'"http_x_forwarded_for"';

#access_log logs/access.log main;


sendfile on;


#tcp_nopush on;


#keepalive_timeout 0;


keepalive_timeout 65;


#gzip on;

定义作为 web 服务器的相关属性 可以有多个

server {

监听的端口

listen 80;

服务名称

server_name localhost;

字符集

#charset koi8-r;


#access_log logs/host.access.log main;

定义一个虚拟主机的属性,所有的 web 服务必须定义成一个虚拟主机

location / {

资源存放的根目录在 html 文件夹下

root html;

欢迎页

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 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 的虚拟主机配置


=============


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

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享


==============================================================


了解了 nginx.conf 核心配置文件中基础的内容后,我们来看看这样一个需求,比如说我们现在要搭建三个服务,分别是 bbs 服务,门户系统和公司内部系统,这时我们可以通过三个 web 服务来搭建,但为了方便我们可以利用 nginx 的虚拟主机来实现这三个服务,具体怎么做呢?如下:



1.首先在 nginx 的根目录下创建三个文件夹:bbs,edu,www



2.分别在这三个文件夹中放入对应的资源文件,我们随便放入一个 html 页面即可(能区别即可)



3.修改 nginx.conf 配置文件,添加三个 server 配置


server {


listen 80;

虚拟主机配置

server_name bbs.gupao.com;

最后

学习视频:



大厂面试真题:



本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

用户头像

MySQL神话

关注

还未添加个人签名 2021.11.12 加入

还未添加个人简介

评论

发布
暂无评论
Nginx核心配置文件介绍,rabbitmq面试题