events {
使用的网络I/O模型,Linux推荐使用epoll模式 FreeBSD推荐使用kqueue模型
use epoll;
单个woker进程支持的最大连接数
worker_connections 1024;
}
【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - r e m o t e u s e r [ remote_user [ remoteuser[time_local] “$request” ’
'$status b o d y b y t e s s e n t " body_bytes_sent " bodybytessent"http_referer" ’
‘“ h t t p u s e r a g e n t " " http_user_agent" " httpuseragent""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.conf核心配置文件中基础的内容后,我们来看看这样一个需求,比如说我们现在要搭建三个服务,分别是bbs服务,门户系统和公司内部系统,这时我们可以通过三个web服务来搭建,但为了方便我们可以利用nginx的虚拟主机来实现这三个服务,具体怎么做呢?如下:
1.首先在nginx的根目录下创建三个文件夹:bbs,edu,www
2.分别在这三个文件夹中放入对应的资源文件,我们随便放入一个html页面即可(能区别即可)
3.修改nginx.conf配置文件,添加三个server配置
server {
listen 80;
虚拟主机配置
server_name bbs.gupao.com;
#charset koi8-r;
#access_log logs/host.access.log main;
虚拟主机对应的服务的资源地址
root /usr/local/nginx/bbs;
location / {
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;
}
}