Nginx服务

一、 nginx概述

  性能优于apache,高并发性,单台物理主机最高可处理50000个并发请求;采用epoll模型,对系统资源利用率提高。nginx不单单能做网站服务,而且可以作为代理服务。

二、 nginx安装

 

  yum安装与配置

    配置yum

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

  若想要保存rpm包,修改如下设置:

vim /etc/yum.conf

keepcache=1

  安装nginx

    yum install -y nginx

  启动nginx

    systemctl start nginx && systemctl enable nginx

  查看nginx监听

netstat -anptu | grep nginx

80

  nginx配置文件

    /etc/nginx/nginx.conf

 

  user  nginx; //指定nginx运行用户

  worker_processes  1; //指定工作进程

 

error_log  /var/log/nginx/error.log warn; //错误日志

pid        /var/run/nginx.pid; //pid存储路径

 

 

events {

    worker_connections  1024; //每一个工作进程能处理的连接请求数量

}

 

 

http { //定义httpd协议

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    access_log  /var/log/nginx/access.log  main;

 

    sendfile        on;

    #tcp_nopush     on;

 

    keepalive_timeout  65;

 

    #gzip  on;

 

    include /etc/nginx/conf.d/*.conf; //调用外部配置文件

}

 

/etc/nginx/conf.d/default.conf

server { //定义网站主机头。每一个server字段代表一个网站

    listen       80; //监听

    server_name  localhost; //网站域名

 

    #charset koi8-r; //字符编码

    #access_log  /var/log/nginx/host.access.log  main; //访问成功日志

 

    location / { //定义根文档目录

        root   /usr/share/nginx/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   /usr/share/nginx/html;

    }

 

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ \.php$ { //定义nginx解析php页面的代理服务器,LAMP平台

    #    proxy_pass   http://127.0.0.1;

    #}

 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    #location ~ \.php$ { //利用fpm模块来解析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;

    #}

}

 

posted @ 2021-09-23 20:08  天才小2b  阅读(78)  评论(0编辑  收藏  举报