|
| 1 | +# centos7安装nginx |
| 2 | +[参考Nginx安装](https://www.nginx.cn/install) |
| 3 | +## 1.centos平台编译环境使用如下指令 |
| 4 | +```python |
| 5 | +# 安装make |
| 6 | +yum -y install gcc automake autoconf libtool make |
| 7 | +# 安装g++ |
| 8 | +yum install gcc gcc-c++ |
| 9 | +``` |
| 10 | + |
| 11 | +## 2.开始安装 |
| 12 | +* 选定源码目录 |
| 13 | +* 安装PCRE库 |
| 14 | +* 安装zlib库 |
| 15 | +* 安装ssl |
| 16 | +* 安装nginx |
| 17 | + |
| 18 | +#### 2.1.选定源码目录 |
| 19 | +```python |
| 20 | +# 指定源码的目录 |
| 21 | +cd /usr/local/src |
| 22 | +``` |
| 23 | +#### 2.2.安装PCRE库 |
| 24 | +```python |
| 25 | +cd /usr/local/src |
| 26 | +wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz |
| 27 | +tar -zxvf pcre-8.44.tar.gz |
| 28 | +cd pcre-8.44 |
| 29 | +./configure |
| 30 | +make |
| 31 | +make install |
| 32 | +``` |
| 33 | +#### 2.3.安装zlib |
| 34 | +```python |
| 35 | +wget http://zlib.net/zlib-1.2.11.tar.gz |
| 36 | +tar -zxvf zlib-1.2.11.tar.gz |
| 37 | +cd zlib-1.2.11 |
| 38 | +./configure |
| 39 | +make |
| 40 | +make install |
| 41 | +``` |
| 42 | +#### 2.4.安装ssl |
| 43 | +```python |
| 44 | +wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz |
| 45 | +tar -zxvf openssl-1.1.1g.tar.gz |
| 46 | +cd openssl-1.1.1g |
| 47 | +./config |
| 48 | +make |
| 49 | +make install |
| 50 | +``` |
| 51 | +#### 2.5.安装nginx |
| 52 | +```python |
| 53 | +wget http://nginx.org/download/nginx-1.18.0.tar.gz |
| 54 | +tar -zxvf nginx-1.18.0.tar.gz |
| 55 | +cd nginx-1.18.0 |
| 56 | + |
| 57 | +# 默认安装 |
| 58 | +./configure & make & make install |
| 59 | + |
| 60 | +# 自定义编译安装 |
| 61 | +# ./configure --sbin-path=/usr/local/nginx/nginx \ |
| 62 | +# --conf-path=/usr/local/nginx/nginx.conf \ |
| 63 | +# --pid-path=/usr/local/nginx/nginx.pid \ |
| 64 | +# --with-http_gzip_static_module \ |
| 65 | +# --with-http_stub_status_module \ |
| 66 | +# --with-file-aio \ |
| 67 | +# --with-http_realip_module \ |
| 68 | +# --with-http_ssl_module \ |
| 69 | +# --with-pcre=/usr/local/src/pcre-8.44 \ |
| 70 | +# --with-zlib=/usr/local/src/zlib-1.2.11 \ |
| 71 | +# --with-openssl=/usr/local/src/openssl-1.1.1g |
| 72 | + |
| 73 | +# make |
| 74 | +# make install |
| 75 | +``` |
| 76 | + |
| 77 | +**Nginx编译选项** |
| 78 | + |
| 79 | +* --prefix=path: 自定义nginx的安装目录,默认/usr/local/nginx |
| 80 | +* --sbin-path=path:定义nginx可执行文件的路径,默认prefix/sbin/nginx |
| 81 | +* --conf-path=path:设置nginx.conf配置文件路径,默认prefix/conf/nginx.conf,可以通过nginx -c config_path,启动的时候指定配置文件 |
| 82 | +* --pid-path=path: 设置nginx.pid文件,将存储的主进程的进程号,默认prefix/logs/nginx.pid |
| 83 | +* --error-log-path=path: 设置主错误,警告,和诊断文件的名称,默认prefix/logs/error.log |
| 84 | +* --http-log-path=path: 设置主请求的HTTP服务器的日志文件的名称,默认prefix/logs/access.log |
| 85 | +* --user=name 设置nginx工作进程的用户,默认nobody |
| 86 | +* --group=name 设置nginx工作进程的用户组 |
| 87 | +* --with-pcre=/usr/local/src/pcre-8.44: 指定pcre源码路径 |
| 88 | +* --with-zlib=/usr/local/src/zlib-1.2.11: 指定zlib源码路径 |
| 89 | +* --with-openssl=/usr/local/src/openssl-1.1.1g: 指定ssl源码路径 |
| 90 | + |
| 91 | +## 3.运行nginx |
| 92 | +```python |
| 93 | +[root@iZ8vb6ughzbdqkfd58dowoZ nginx]# ls |
| 94 | +client_body_temp fastcgi.conf.default fastcgi_temp koi-win mime.types.default nginx.conf.default sbin scgi_temp uwsgi_temp |
| 95 | +conf fastcgi_params html logs nginx nginx.pid scgi_params uwsgi_params win-utf |
| 96 | +fastcgi.conf fastcgi_params.default koi-utf mime.types nginx.conf proxy_temp scgi_params.default uwsgi_params.default |
| 97 | +[root@iZ8vb6ughzbdqkfd58dowoZ nginx]# ./nginx |
| 98 | +``` |
| 99 | + |
| 100 | +* 启动: /usr/local/nginx/sbin/nginx |
| 101 | +* 停止/重启: /usr/local/nginx/sbin/nginx -s stop(quit、reload) |
| 102 | +* 帮助: /usr/local/nginx/sbin/nginx -h |
| 103 | +* 配置文件: vim /usr/local/nginx/conf/nginx.conf |
0 commit comments