一:下载nginx(下载可能会有点慢,耐心等待)
官网地址:http://nginx.org/en/download.html
二:解压并安装
- 安装依赖(安装过的跳过)
复制代码
1
2yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel open openssl-devel
- 导入并解压:tar -zxvf nginx-1.20.2.tar.gz
- 编译执行configure文件
复制代码
1
2
3
4
5# 不用https执行指令 ./configure --with-http_ssl_module # 需要使用https执行 ./configure
- 编译执行make命令
复制代码
1
2
3make make install
- 创建日志文件
复制代码
1
2mkdir ./usr/local/nginx/logs
三:配置nginx.conf
复制代码
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99user root; worker_processes auto; # 错误日志 error_log logs/error.log; #nginx.pid文件 pid logs/nginx.pid; events { worker_connections 1024; } 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 logs/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include mime.types; default_type application/octet-stream; server { listen 80; listen [::]:80; server_name test.cn; location / { index index.html; alias /usr/test/; autoindex on; } error_page 404 /404.html; } server { listen 80; listen [::]:80; server_name test.cn; ssl_certificate /test.cn.pem; ssl_certificate_key /test.cn.key; location / { proxy_pass http://localhost:8801/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; # 将此路由请求的实体大小限制为20m client_max_body_size 20m; } error_page 404 /404.html; } server { listen 443 ssl; server_name test.cn; #证书文件 ssl_certificate /test.cn.pem; ssl_certificate_key /test.cn.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!aNULL:!eNULL; location / { proxy_pass http://localhost:8801/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; # 将此路由请求的实体大小限制为20m client_max_body_size 20m; } error_page 404 /404.html; } }
四:启动/停止
- 启动
复制代码
1
2
3
4
5
6cd /usr/local/nginx/sbin # 默认配置文件启动 ./nginx # 指定配置文件启动 ./nginx -c /usr/local/nginx/conf/nginx.conf
- 停止
复制代码
1
2
3
4cd /usr/local/nginx/sbin # 停止指令 ./nginx -s stop
最后
以上就是无语砖头最近收集整理的关于linux nginx 安装 及 配置的全部内容,更多相关linux内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复