子嘉的博客 子嘉的博客
首页
bic-bic
技术
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

高子嘉

没有比脚更长的路,没有比人更高的山
首页
bic-bic
技术
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 技术文档

  • GitHub技巧

  • 博客搭建

  • 服务端

    • deploy
    • nginx
      • 安装依赖
      • 安装 nginx
      • 配置
    • vim
    • vimrc
    • gtest
  • distributed

  • golang

  • db

  • docker

  • linux

  • 技术
  • 服务端
子嘉
2022-06-05
目录

nginx

Nginx 官网 (opens new window)

# 安装依赖

  1. 安装 gcc-c++编译器
yum install -y zlibyum gcc-c++
yum install -y openssl openssl-devel zlib-devel
1
2
  1. 安装 pcre 包
yum install -y pcre pcre-devel
1
  1. 安装 zlib 包
yum install -y zlib zlib-devel
1

# 安装 nginx

  1. 下载nginx 包 (opens new window)
wget http://nginx.org/download/nginx-1.22.0.tar.gz
1
  1. 解压
tar -zxvf /usr/local/nginx-1.21.0
1
  1. 进入刚解压的目录
cd nginx-1.21.0
1
  1. 使用 nginx 默认配置安装
./configure  --with-http_stub_status_module --with-http_ssl_module
1
  1. 安装
make;
make install;
1
2
  1. 查找安装路径
whereis nginx
1
  1. 进入目录
cd /usr/local/nginx/sbin
1
  1. 直接启动 nginx
./nginx
# 查看是否启动
ps -ef | grep nginx
1
2
3
  1. 使用systemctl管理

创建文件 /etc/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

启动重启命令

sudo systemctl enable nginx
sudo systemctl start nginx
1
2

# 配置

nginx https 配置示例1(拷贝自阿里云)

#以下属性中,以ssl开头的属性表示与证书配置有关。
server {
    listen 443 ssl;
    #配置HTTPS的默认访问端口为443。
    #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
    #如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。
    server_name yourdomain.com; #需要将yourdomain.com替换成证书绑定的域名。
    root html;
    index index.html index.htm;
    ssl_certificate cert/cert-file-name.pem;  #需要将cert-file-name.pem替换成已上传的证书文件的名称。
    ssl_certificate_key cert/cert-file-name.key; #需要将cert-file-name.key替换成已上传的证书密钥文件的名称。
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    #表示使用的加密套件的类型。
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
    ssl_prefer_server_ciphers on;
    location / {
        root html;  #站点目录。
        index index.html index.htm;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

nginx https 配置示例2

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /family/ {
            proxy_pass http://family;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }


    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  api.family.farmergao.cn;

        ssl_certificate      cert/api.family.farmergao.cn.pem;
        ssl_certificate_key  cert/api.family.farmergao.cn.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        #ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_prefer_server_ciphers  on;

        location /family/ {
            proxy_pass http://family;
        }
    }

    upstream family {
        server  localhost:8080 max_fails=5 fail_timeout=100;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
编辑 (opens new window)
#nginx
上次更新: 2024/01/17, 10:57:24
deploy
vim

← deploy vim→

最近更新
01
mongodb restore
03-06
02
pytesseract
02-28
03
consul
02-24
更多文章>
Theme by Vdoing | Copyright © 2022-2025 子嘉 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式