Detailed steps and website configuration for installing Nginx1.17.8 on CentOS7

If you have not configured the initial environment of the centos system, you need to manually install the packages required by Nginx. Some modules of nginx rely on some lib libraries, so before installing nginx, you must first install these lib libraries: including PCRE regular expressions, secure socket layer password libraries, and some common software packages, etc.

nginx website: http://nginx.org/
If you have not configured the initial environment of the centos system, you need to install it manuallyRequired packages.
Some modules of nginx depend on some lib libraries, so before installing nginx, you must install these lib libraries: including PCRE regular expressions, secure socket layer password libraries, and some common software packages, etc. If you have built the environment before, please ignore the following and go to the next step directly.

yum install gcc gcc-c++ yum -y install pcre pcre-devel yum install zlib zlib-devel yum install openssl openssl --devel yum make wget

Download the latest version of Nginx1.17.8

wget http://nginx.org/download/nginx-1.17.8.tar.gz
tar -zxvf nginx-1.17.8.tar.gz cd nginx-1.17.8

Cancel Debug compilation mode

vim auto/cc/gcc

#CFLAGS="$CFLAGS -g" Comment out this sentence with #.
EditInstallation

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
make make install

Test whether the installation was successful:

cd /usr/local/nginx/sbin

Enter the nginx directory and type ./nginx -t or /usr/local/nginx/sbin/nginx -t
Set Nginx to start automatically at boot:

vi /lib/systemd/system/nginx.service

Create a nginx.service file

[Unit] Description=nginx - high performance web server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop [Install] WantedBy=multi-user.target

Set nginx to start up and make the configuration take effect:

systemctl enable nginx.service

Edit and configure nginx, open the Nginx configuration file

vi /usr/local/nginx/conf/nginx.conf

Replace the code in the nginx.conf file with the following code. This is just a simple configuration file that supports http access and PHP access.

user www www; worker_processes 1; pid logs/nginx.pid; events { use epoll; worker_connections 2048; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; # gzip compression function settings gzip on; gzip_http_version 1.0; gzip_comp_level 6; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { listen 80; server_name website domain name; client_max_body_size 10M; root /var/www/; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri =404; include fastcgi.conf; fastcgi_pass 127.0.0.1:9000; } } }

Start Nginx

systemctl start nginx

Create a WWW directory under the VAR directory of the server, then create a new index.php file in the WWW directory, copy and paste the following content into index.php, and save!

The /var/www directory is where we configure Nginx to access the website. This directory must correspond to the one set in nginx.conf, and can be set at will!

phpinfo();

?>

After saving index.php, enter the server's IP address, or set the bound domain name. The domain name must be resolved and take effect before it can be used.

After entering the IP or domain name in the browser, you can open the PHP probe page.

On the probe page, you can view some package information and installation directory of PHP. OK, Nginx with PHP support is installed! Next, install other software!

 

The following are the control commands for Nginx:
systemctl start nginx

systemctl stop nginx

systemctl reload nginx Restart does not need to stop the nginx service to make the modified configuration take effect

systemctl restart nginx

systemctl enable nginx Set to start at boot

systemctl disable nginx disables boot

systemctl status nginx View service status

1/5 - (1 vote)

Leave a Reply

Your email address will not be published. Required fields are marked *