Install dependencies:
- yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
Download nginx:
- wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
- tar -zxvf nginx-1.10.1.tar.gz
- cd nginx-1.10.1
Configure nginx:
1. Default configuration
- ./configure
2. Custom configuration
First, execute nginx -V to print out the current configuration, for example:
./configure --prefix=/usr/local/nginx. --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/conf/nginx.pid --lock-path=/var/lock/nginx
Add the configuration you want, such as ssl, and re-execute
./configure --prefix=/usr/local/nginx. --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/conf/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module
Compile and install nginx:
Set up nginx to boot and start:
- vi /etc/rc.local
In the rc.local file write:
- /usr/local/nginx/sbin/nginx
Set startup file permissions:
- chmod 755 /etc/rc.local
Start and stop nginx commands:
- cd /usr/local/nginx/sbin/
- ./nginx
- ./nginx -s stop
- ./nginx -s quit
- ./nginx -s reload
nginx seamlessly upgrade https:
1. Check whether nginx supports ssl: 1. Check whether nginx supports ssl:
- /usr/local/nginx/sbin/nginx -V
2. Because this is an upgrade of nginx, there is no need to execute make install. First, back up the original nginx execution script:
- mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
3. Copy the newly compiled nginx execution script to the corresponding directory:
- cd objs /
- cp nginx /usr/local/nginx/sbin/
4. Finally, smooth upgrade
- cd ..
- make upgrade
5. Edit the configuration file
- cd /usr/local/nginx/conf
- vim nginx.conf
- listen 443;
- server_name domain name;
- index index.html index.htm index.php;
- root project root path;
- ssl on;
- ssl_certificate certificate path and file;
- ssl_certificate_key certificate path and file;
- ssl_session_timeout 5m;
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
- ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256: HIGH:! aNULL:! MD5:! RC4:! DHE;
- ssl_prefer_server_ciphers on;