Compile and install nginx1.7.8 in centos 7
The installation environment is: Minimize the installed centos7 and disable seliunx.
Minimal centos installation:
:http://mirrors.yun-idc.com/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-Minimal.iso
Disable selinux
sed –i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
Start nginx1.7.8 Installation
Create a group groupadd www to create a user, do not allow login and do not create a home directory useradd-s/sbin/nologin-g www-M www # download the latest nginxwget-C http://nginx.org/download/nginx-1.7.8.tar.gztar zxvf nginx-1.7.8.tar.gz # compile nginx that can basically run. /configure -- user = www -- group = www -- prefix =/usr/local/nginx -- with-http_stub_status_module -- with-http_ssl_module -- with-http_gzip_static_modulemakemake install
If an error occurs:
./Configure: error: C compiler cc is not found
Solution:
yum install gcc gcc-c++
If an error occurs:
./Configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using-without-http_rewrite_module
Option, or install the PCRE library into the system, or build the PCRE library
Statically from the source with nginx by using-with-pcre = <path> option.
Solution:
yum install pcre-devel
If an error occurs:
./Configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
Into the system, or build the OpenSSL library statically from the source
With nginx by using-with-openssl = <path> option.
Solution:
yum install openssl-devel
After the preceding error messages are solved in sequence: run again
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_modulemakemeke install
Compilation parameter explanation:
# Specify the user who runs permission -- user = www # specify the permission user group for running -- group = www # specify the installation path -- prefix =/usr/local/nginx # support nginx status query -- with-http_stub_status_module # enable ssl support -- with-http_ssl_module # enable GZIP feature -- with-http_gzip_static_module
Therefore, the dependencies that must be installed through nginx compilation and installation must be:
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel
2. Add scripts for nginx startup, restart, and reload configuration in centos7
Nginx Direct start method:
/usr/local/nginx/sbin/nginx
However, it is not very convenient. Therefore, it is more reasonable to use the following script to control nginx startup, shutdown, and overloading.
Edit the file: vim/usr/lib/systemd/system/nginx. service. Add the following script. Note the path!
[Unit]Description=nginx - high performance web serverDocumentation=http://nginx.org/en/docs/After=network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.confExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target
How to Use systemctl:
Systemctl is-enabled servicename. service # query whether the service starts systemctl enable xxx. service # Start and run the systemctl disable xxx service. service # cancel starting systemctl start xxx. service # Start the systemctl stop xxx service. service # Stop service systemctl restart xxx. service # restart the systemctl reload xxx service. service # reload the service configuration file systemctl status xxx. service # query the service running status systemctl -- failed # display the service that failed to start
Therefore, after adding the above script, the methods for operating nginx in centos7 are as follows:
Systemctl is-enabled nginx. service # Check whether systemctl enable nginx is enabled when nginx is started. service # Start nginxsystemctl disable nginx. service # cancel startup and run nginxsystemctl start nginx. service # Start nginxsystemctl stop nginx. service # Stop nginxsystemctl restart nginx. service # restart nginxsystemctl reload nginx. service # reload the nginx configuration file systemctl status nginx. service # query nginx running status systemctl -- failed # display services that failed to start