Nginx 服务器

应用软件的总类

桌面应用

word 
excel
axure
cad
WPS运维工程师

C/S 客户端服务器架构

微信
钉钉
Navicat + mysql(Oracle)

80% B/S 浏览器 + 服务器

  • 协议 http协议 (80/443)
    基于超文本协议。
    发请求方式

      GET,POST,PUT,DELETE,
      > URL Uniform Reource Locator
      > URI Uniform Resoruce Identifile

    接受请求

      状态码值
          200 OK
          2XX 表示成功
          3xx 表示警告,告知
              301跳转
              302页面缓冲
              303
              304
    
          404 文件找不到。资源找不到
              4xx 表示客户端访问错误。
              403 forbidden
              499 客户端提前关闭
              451 因为法律原因不可以
              401 
    
          5xx 系统内部错误,web服务器或者应用服务器坏了            
              502 上游服务器不通,服务器不可达
    
              503 service unavialble 服务不可用

    基于TCP协议,但http协议是无连接的。

web服务器的种类

  1. Apache httpd
  2. Nginx(俄罗斯人写的)
  3. IIS(微软)
  4. Xitami
  5. httplight

Nginx 服务器

1。 web 服务器,网站
2。 非常优秀代理服务器,负载均衡服务器。

应用服务器 Application Server Apps

Java: tomcat,glashfish ,jboss,weblogic,webspere.
Pytnon: cgi
Php: fastcgi
Ruby:
Go
.NET

安装nginx

因为nginx不在默认的仓库里面,并且由于centos7不再被支持,所有的话库里没有nginx,nginx有很多的仓库,我们一般采用epel-release库。

    yum -y install epel-release
    yum -y install nginx
启动nginx
[root@master ~]# nginx -s stop
[root@master ~]# nginx -s reload
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
[root@master ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@master ~]# nginx -v
nginx version: nginx/1.20.1
[root@master ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-
配置Nginx

nginx配置文件 /etc/nginx/nginx.conf

1024以下的端口启动,必须使用root
80 http
443 https
53 dns
110 pop3
25 smtp
22 ssh
21 telnet
23 ftp
3306 mysql
1521 oracle
1433 sqlserver micosoft
50000 gaussdb
10000 hive
8080 tomcat
30000以上,k8s使用。
5432 posgres
2181 zk

nginx配置文件
[TOC]
# Nginx 服务器
## 应用软件的总类
### 桌面应用 
    word 
    excel
    axure
    cad
    WPS运维工程师

### C/S 客户端服务器架构
    微信
    钉钉
    Navicat + mysql(Oracle)


### 80% B/S 浏览器 + 服务器
- 协议 http协议 (80/443)
    基于超文本协议。
    发请求方式
        GET,POST,PUT,DELETE,
        > URL Uniform Reource Locator
        > URI Uniform Resoruce Identifile

    接受请求
        状态码值
            200 OK
            2XX 表示成功
            3xx 表示警告,告知
                301跳转
                302页面缓冲
                303
                304

            404 文件找不到。资源找不到
                4xx 表示客户端访问错误。
                403 forbidden
                499 客户端提前关闭
                451 因为法律原因不可以
                401 

            5xx 系统内部错误,web服务器或者应用服务器坏了            
                502 上游服务器不通,服务器不可达

                503 service unavialble 服务不可用
    基于TCP协议,但http协议是无连接的。


### web服务器的种类

1. Apache httpd
2. Nginx(俄罗斯人写的)
3. IIS(微软)
4. Xitami
5. httplight

#### Nginx 服务器
1。 web 服务器,网站
2。 非常优秀代理服务器,负载均衡服务器。


##### 安装nginx
因为nginx不在默认的仓库里面,并且由于centos7不再被支持,所有的话库里没有nginx,nginx有很多的仓库,我们一般采用epel-release库。
yum -y install epel-release
yum -y install nginx
##### 启动nginx

[root@master ~]# nginx -s stop
[root@master ~]# nginx -s reload
nginx: [error] open() “/run/nginx.pid” failed (2: No such file or directory)
[root@master ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@master ~]# nginx -v
nginx version: nginx/1.20.1
[root@master ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: –prefix=/usr/share/nginx –sbin-path=/usr/sbin/nginx –modules-path=/usr/lib64/nginx/modules –conf-

配置Nginx

nginx配置文件 /etc/nginx/nginx.conf

1024以下的端口启动,必须使用root
80 http
443 https
53 dns
110 pop3
25 smtp
22 ssh
21 telnet
23 ftp
3306 mysql
1521 oracle
1433 sqlserver micosoft
50000 gaussdb
10000 hive
8080 tomcat
30000以上,k8s使用。
5432 posgres
2181 zk

配置文件
user nginx;  # 用户 
worker_processes 3; # 内核数量,进程数
error_log /var/log/nginx/error.log;  # 错误日志
pid /run/nginx.pid; # 进程文件

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; # 包含

events {
    worker_connections 1024; # 一个工作进程数量,从连接数=worker_connection * worker_processes 
}
# 指令 directive 
http {
    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; 
    tcp_nodelay         on; 
    keepalive_timeout   65; 
# 频繁连接会导致开销很大,因为连接有三次握手,四次挥手。
# 这个要掌握。
# http1.1.连接复用、增加吞吐量。
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
 # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }


####修改本地dns,
windows下
C:\Windows\System32\drivers\etc

windows下修改这个文件必须使用超级用户。

linux下
/etc/hosts

模板王
https://www.mobanwang.com/

安装步骤

1、删除nginx.conf里面默认网站

  1. 创建2个网址,www.qq.com /www.baidu.com,www.dengsheng.com

  2. 在/etc/nginx/conf.d/目录下,创建2个文件,必须以conf结尾,内容example如下。


   server {
        listen       80;
          server_name  $your_domain;
        root         /var/www/html/$your_domain/;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

    }
  1. 修改windows的下的dns文件,hosts文件,
    3.1 下载模板rar文件,想办法上传到server的root目录
  2. nginx -t检查配置是否正确
    5 nginx -s reload 重新启动
    6、 Edge访问是否成功。

linux + nginx+ mysql +php

LNMP

linux + apache+ mysql +php

LAMP

作者:严锋  创建时间:2025-04-16 09:17
最后编辑:严锋  更新时间:2025-05-09 15:48