Centos7.6
nginx-1.17.0
官网:http://nginx.org/download/nginx-1.17.0.tar.gz
在安装nginx
前首先要确认系统中是否安装gcc
、pcre-devel
、zlib-devel
、openssl-devel
yum list installed | grep xxx
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
上图为已安装
nginx-1.17.0.tar.gz
上传至服务器并解压tar -xzvf nginx-1.17.0.tar.gz
解压后如下所示:
nginx
目录下编译安装nginx
./configure --prefix=/usr/local/nginx1.17.0 --conf-path=/usr/local/nginx1.17.0/nginx.conf --with-http_stub_status_module --with-http_ssl_module
--with-http_ssl_module
配置nginx
支持https
协议访问,不使用https
可以不用添加该命令
该命令编译nginx
时将配置文件nginx.conf
生成在nginx
目录下,因编译后出现错误,采用这种方式,详见后面错误记录,因此,nginx
的配置文件不再是conf
中的nginx.conf
make
,make install
编译make
make install
./sbin/nginx -t
nginx
./sbin/nginx
nginx
./sbin/nginx -s stop
nginx
./sbin/nginx -s reload
nginx
进程ps -ef | grep nginx
IP
(nginx
默认端口为80
),出现如下界面则证明成功openssl
,openssl-devel
yum install openssl openssl-devel
mkdir /usr/local/nginx/conf/ssl
openssl genrsa -des3 -out server.key 2048 #根据提示输入证书口令
CSR
)openssl req -new -key server.key -out server.csr #输入上面设置的口令,根据提示输入相应的信息
key
进行解密openssl rsa -in server.key -out server_nopasswd.key
CSR
openssl x509 -req -days 365 -in server.csr -signkey server_nopasswd.key -out server.crt
vim
修改nginx
配置文件,加载ssl
证书server {
listen 443 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx-1.17.0/conf/ssl/server.crt;
ssl_certificate_key /usr/local/nginx-1.17.0/conf/ssl/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
输入证书密码启动nginx
浏览器访问测试:https://服务器IP + 端口443
,出现如下界面则成功
nginx
报错:cp: `conf/koi-win‘ and `/usr/local/nginx/conf/koi-win‘ are the same file
该错误为编译安装nginx
时没有指定conf-path
出现的,出现问题的命令:
./configure --prefix=/usr/local/nginx1.17.0 --with-http_stub_status_module --with-http_ssl_module
将命令改为如下指定conf-path
后正常:
./configure --prefix=/usr/local/nginx1.17.0 --conf-path=/usr/local/nginx1.17.0/nginx.conf --with-http_stub_status_module --with-http_ssl_module
暂不知具体原因,感谢大佬
centos安装nginx 报错:cp: ‘conf/koi-win‘ and ‘/usr/local/nginx/conf/koi-win‘ are the same file
.end
原文:https://www.cnblogs.com/maggieq8324/p/13817399.html