CentOS 7安装并配置Nginx

news/2024/7/5 1:07:55

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。

Nginx的安装

1、首先要添加`CentOS EPEL`仓库,直接复制执行:

yum -y install epel-release

2、现在`Nginx`存储库已经安装在您的服务器上,使用以下`yum`命令安装:

yum -y install nginx

3、`CentOS7`启动`Nginx`并查看状态: ``` 启动:systemctl start nginx 查看:systemctl status nginx ```

4、在浏览器输入IP地址可以看到下图,证明 Nginx启动成功。

### 5、Nginx站点目录是`/usr/share/nginx/html`,配置文件目录是`/etc/nginx`,下面的`.conf`文件都是配置文件。
### 6、基本配置文件。
### 7、完整配置文件

#user administrator administrators;  #配置用户或者组,默认为nobody nobody。
#worker_processes 2;  #允许生成的进程数,默认为1
#pid /nginx/pid/nginx.pid;   #指定nginx进程运行文件存放地址
error_log log/error.log debug;  #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
events {
    accept_mutex on;   #设置网路连接序列化,防止惊群现象发生,默认为on
    multi_accept on;  #设置一个进程是否同时接受多个网络连接,默认为off
    #use epoll;      #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
    worker_connections  1024;    #最大连接数,默认为512
}
http {
    include       mime.types;   #文件扩展名与文件类型映射表
    default_type  application/octet-stream; #默认文件类型,默认为text/plain
    #access_log off; #取消服务日志    
    log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定义格式
    access_log log/access.log myFormat;  #combined为日志格式的默认值
    sendfile on;   #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
    sendfile_max_chunk 100k;  #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。
    keepalive_timeout 65;  #连接超时时间,默认为75s,可以在http,server,location块。

    upstream mysvr {   
      server 127.0.0.1:7878;
      server 192.168.10.121:3333 backup;  #热备
    }
    error_page 404 https://www.baidu.com; #错误页
    server {
        keepalive_requests 120; #单连接请求上限次数。
        listen       4545;   #监听端口
        server_name  127.0.0.1;   #监听地址       
        location  ~*^.+$ {       #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
           #root path;  #根目录
           #index vv.txt;  #设置默认页
           proxy_pass  http://mysvr;  #请求转向mysvr 定义的服务器列表
           deny 127.0.0.1;  #拒绝的ip
           allow 172.18.5.54; #允许的ip           
        } 
    }
}

http://www.niftyadmin.cn/n/3649359.html

相关文章

spring react_如何使用React Spring创建动画的React应用

spring react介绍 (Introduction) Animations add life to your applications and improve the overall user experience. React Spring is an animation package that uses spring-like physics in its core animations to make it easily configurable. Springs are cumulati…

[GOLF]过了磨合期了

今日到了4S店,换了三滤,检查了胎压和空调。换了三滤果然很见效,回去的路上,就觉得爱车凶猛了许多,很给劲儿。第一次开着车去了王府井,并且第一次停到了收费的地下停车场,蜿蜒着下到地下&#xf…

CentOS 7搭建PHP环境

PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领…

Android Context 详解

Android中context可以作很多操作,但是最主要的功能是加载和访问资源。 在android中有两种context,一种是application context,一种是activity context,通常我们在各种类和方法间传递的是activity context。 继承关系:…

如何在JavaScript中替换字符串的所有实例

介绍 (Introduction) Replacing text in strings is a common task in JavaScript. In this article you’ll look at using replace and regular expressions to replace text. 替换字符串中的文本是JavaScript中的常见任务。 在本文中,您将研究如何使用replace和正…

[C#]I/O完成端口的实现

在VC中我几乎每一个Windows Service都是采用I/O完成端口。至于在C#中如何使用I/O完成端口,一直很少见人提及。William Kennedy的三篇文章《IOCP Thread Pooling in C#》,对实现这种机制很有帮助,唯一美中不足的是,它只能把int数值…

MyEclipse 10破解方法及下载地址

破解地址:http://blog.csdn.net/xexiyong/article/details/8273440 下载地址:http://xiazai.sogou.com/detail/34/16/-3776446113025264156.html?e1970

个人博客搭建教程——基于WordPress

WordPress是使用PHP语言开发的博客平台,是免费开源的。用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可以把WordPress当作一个内容管理系统(CMS)来使用。本教程采用NginxMySQLPHPWordPress搭建个人博客系统。 使用Wor…