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-develyum 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

CSRopenssl 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