ubantu安装nginx
nginx安装
- 下载组件
nginx下载地址
http://nginx.org/en/download.html
打开此网址,然后找到要下载的包,右击复制链接地址然后用如下命令进行操作
sudo wget 复制的链接地址
pcre库下载地址,用于解析正则
sudo wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
zlib下载地址,用来压缩文件
sudo wget http://www.zlib.net/zlib-1.2.11.tar.gz
openssl下载地址,用来解析https协议
https://github.com/openssl/openssl
打开此网址
找到要下载的OpenSSL_101r,然后进行
sudo wget 链接地址
2. 解压安装
在同级目录下,解压安装nginx、zlib、openssl、pcre
tar -zxvf 要解压的包的名称
- 配置安装
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-OpenSSL_1_0_1r
如果出现 ubuntu Invalid C++ compiler or C++ compiler flags 这个错误,请安装 sudo apt-get install g++ 编译安装
$ make && sudo make install
Nginx会被安装在/usr/local/nginx目录下(也可以使用参数–prefix=指定自己需要的位置), 安装成功后 /usr/local/nginx 目录下有四个子目录分别是:conf、html、logs、sbin 。 其中 Nginx 的配置文件存放于 conf/nginx.conf, bin文件是位于 sbin 目录下的 nginx 文件。 确保系统的 80 端口没被其他程序占用,运行 sbin/nginx 命令来启动 Nginx,
- 启动nginx
$sudo /usr/local/nginx/sbin/nginx
打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功