阿里云Linux Ubentu 安装 Nginx并配置https


下载nginx:    wget http://nginx.org/download/nginx-1.8.0.tar.gz
下载openssl : wget http://www.openssl.org/source/openssl-fips-2.0.9.tar.gz
下载zlib    : wget http://www.zlib.net/fossils/zlib-1.2.8.tar.gz
下载pcre    : wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
如果没有安装c++编译环境,还得安装,通过yum install gcc-c++完成安装

下一步,编译安装
openssl :

[root@localhost] tar zxvf openssl-fips-2.0.9.tar.gz

[root@localhost] cd openssl-fips-2.0.9

[root@localhost] ./config && make && make install

[root@localhost] cd ..
pcre:

[root@localhost] tar zxvf pcre-8.38.tar.gz

[root@localhost] cd pcre-8.38

[root@localhost]  ./configure && make && make install

[root@localhost] cd ..

zlib:

[root@localhost]  tar zxvf zlib-1.2.8.tar.gz

[root@localhost] cd zlib-1.2.8

[root@localhost]  ./configure && make && make install

[root@localhost] cd ..

最后安装nginx

[root@localhost]  tar zxvf nginx-1.8.0.tar.gz

[root@localhost] cd nginx-1.8.0

[root@localhost]  ./configure && make && make install


   启动nginx
/usr/local/nginx/sbin/nginx

操作

启动
/usr/local/nginx/sbin/nginx

重启
/usr/local/nginx/sbin/nginx -s reload

停止
/usr/local/nginx/sbin/nginx -s stop


配置文件路径
/usr/local/nginx/conf/nginx.conf

出现错误提示
[root@localhost lib]# error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory


   原因   在RedHat 64位机器上nginx读取的pcre文件为/lib64/libpcre.so.1文件,默认安装pcre时libpcre.so文件安装在/usr/local/lib/目录下,所以输入/opt/nginx/sbin/nginx -V 找不到文件路径!!
        1.首先确定安装了pcre.
        2.切换路径: cd /usr/local/lib  执行   ln -s /usr/local/lib/libpcre.so.1 /lib64/
        3.root权限下添加软链接 /usr/local/lib/libpcre.so.1 到 /lib64/ :  ln -s /usr/local/lib/libpcre.so.1 /lib64/

配置https

nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:102

到解压的nginx目录下

./configure --with-http_ssl_module

当执行上面语句,出现./configure: error: SSL modules require the OpenSSL library.

更新源: apt-get update

sudo apt-get install openssl 
sudo apt-get install libssl-dev

重新执行./configure --with-http_ssl_module

make ,切记不能make install 会覆盖。

把原来nginx备份

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

把新的nginx覆盖旧的

cp objs/nginx /usr/local/nginx/sbin/nginx

出现错误时cp: cannot create regular file ‘/usr/local/nginx/sbin/nginx’: Text file busy

用cp -rfp objs/nginx /usr/local/nginx/sbin/nginx解决

测试nginx是否正确

/usr/local/nginx/sbin/nginx -t

(nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful)

配置好ssl后一定要先停止再启动,不能直接重启命令

/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx

猜你喜欢

转载自blog.csdn.net/Baiychenvip/article/details/84562378