- 安装Nginx相关包
检查是否安装-
pcre(正则语法相关) 和
-
openssl (秘钥证书相关)
-
gcc -v (编译java,c相关)
-
zlib-devel (解压包相关)
-
rpm -qa (qa 为 query 缩写) 也可以 rpm -qa | grep param
-
[root@localhost apache-maven-3.6.1]# rpm -qa pcre
pcre-8.32-17.el7.x86_64
[root@localhost apache-maven-3.6.1]# rpm -qa openssl
openssl-1.0.2k-19.el7.x86_64
[root@localhost nginx-1.12.0]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
如果没有安装
yum install pcre pcre-devel
yum install openssl openssl-devel
yum install gcc-c++
yum -y install zlib-devel
安装Nginx包
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
[root@localhost nginx]# wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
解压
tar zxvf nginx-1.12.0.tar.gz
- 切换到nginx目录下操作configure
[root@localhost nginx]# cd nginx-1.12.0
./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module
报异常: 没有gcc编译工具包
执行
yum install gcc-c++
[root@localhost nginx-1.12.0]# ./configure \
> --prefix=/usr/local/nginx \
> --with-http_ssl_module
checking for OS
+ Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
接着报异常
重复上述命令
./configure
–prefix=/usr/local/nginx
–with-http_ssl_module
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
意思是没有安装pcre,安装了pcre还是报错,
根据提示 没有安装模块 --without-http_rewrite_module 把这个模块加上去
./configure \
--prefix=/usr/local/nginx \
--without-http_rewrite_module \
--with-http_ssl_module
接着报错 openssl -> 安装openssl
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
yum install openssl openssl-devel
再次执行
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre --with-http_ssl_module --without-http_rewrite_module
或者
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre --with-http_ssl_module --without-http_rewrite_module
查看到输出
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
Nginx安装目录下执行编译命令 make
[root@localhost nginx-1.16.1]# make
执行安装命令 make install
[root@localhost nginx-1.16.1]# make install
可以看到刚刚指定nginx生成的目录
[root nginx]# pwd
/usr/local/nginx
[root nginx]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 11月 28 20:59 conf
drwxr-xr-x. 2 root root 40 11月 28 20:59 html
drwxr-xr-x. 2 root root 6 11月 28 20:59 logs
drwxr-xr-x. 2 root root 19 11月 28 20:59 sbin
- 配置环境变量,刚刚生成的目录也是安装地址
whereis nginx
[root nginx]# whereis nginx
nginx: /usr/local/nginx
[root nginx]# ./nginx -v
-bash: ./nginx: 没有那个文件或目录
[root nginx]# vi /etc/profile
最后添加两行
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
环境变量生效
source /etc/profile
[root nginx]# source /etc/profile
- 启动Nginx服务 (sbin下面Nginx为可执行文件,执行./nginx)
[root nginx]# cd sbin/
[root sbin]# ll
总用量 5720
-rwxr-xr-x. 1 root root 5857144 11月 28 20:59 nginx
[root sbin]# ./nginx
[root sbin]# ps -aux | grep nginx
root 15859 0.0 0.0 45960 1120 ? Ss 00:13 0:00 nginx: master process ./nginx
nobody 15860 0.0 0.0 46416 1876 ? S 00:13 0:00 nginx: worker process
root 15862 0.0 0.0 112824 988 pts/0 R+ 00:13 0:00 grep --color=auto nginx
- 浏览器访问
防火墙先开放端口
[root sbin]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root sbin]# firewall-cmd --reload
success
[root sbin]# firewall-cmd --permanent --zone=public --list-ports
8081/tcp 80/tcp
[root sbin]#
输入IP地址
http://192.*..104/
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.