Home  >  Article  >  System Tutorial  >  Original: Centos 7 source code compilation and installation of Nginx 1.13

Original: Centos 7 source code compilation and installation of Nginx 1.13

PHPz
PHPzOriginal
2024-07-16 21:18:31749browse

I won’t go into the relevant introduction of nginx. Since you choose nginx as your web server, you must have different knowledge and understanding of nginx server. Next, I will install it directly.

原创:Centos 7 源码编译安装 Nginx 1.13

Prerequisites

I am using the centos7.3 64-bit core version system. Before installing and configuring nginx, you must install the nginx dependency package. Please see the production chapter of Centos 7 compilation and installation of php7.1, and install the dependency package provided at the beginning of the article. This dependent component package is suitable for any version of Nginx.

Create new web users and groups

$ /usr/sbin/groupadd www
$ /usr/sbin/useradd -g www www
$ ulimit -SHn 65535 //设置linux高负载参数
Download Nginx and OpenSSL from the official website

There are two versions when downloading Nginx: development version and stable version. If it is used for production, download the stable version, http://nginx.org/en/download.html (it is best to download the latest version of the stable version, so there will be bug fixes and new features) I downloaded the latest version nginx-1.13.5.

$ cd /tmp
$ wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
$ tar zxvf openssl-1.1.0e.tar.gz
$ wget https://nginx.org/download/nginx-1.13.5.tar.gz
$ tar zxvf nginx-1.13.5.tar.gz
$ cd nginx-1.13.5
Install Nginx

You may notice that some document tutorials do not assign so many modules when installing nginx (it looks very long), and some do not even assign modules and users. In fact, modules are assigned according to their own needs. If you want If there is no trouble in the future, then just follow the module assignment below. In fact, this is considered all-in-one. Otherwise, you will have to recompile it later if you need it. It is not very troublesome, but it is not easy either. As for whether to assign user groups, I will definitely let you do so. This is related to the availability, security and stability of the nginx configuration.

$ ./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-pcre \
--with-openssl=/tmp/openssl-1.1.0e \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module \
$ make -j8 && make install //编译并安装
Create systemctl system Nginx unit file

After the installation is completed, it needs to be turned on automatically. Otherwise, it needs to be started manually every time, which would be too troublesome.

$ vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP /usr/local/nginx/logs/nginx.pid
ExecStop=/bin/kill -s QUIT /usr/local/nginx/logs/nginx.pid
PrivateTmp=true

[Install]
WantedBy=multi-user.target
保存并退出。
Add auto-start at boot and start Nginx
$ systemctl enable nginx.service
$ systemctl restart nginx.service
Set up Firewalld firewall
$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --reload
Check whether Nginx starts successfully
$ ss -ntlp

You can see that the nginx process is running. At this point, the nginx installation is complete. You may still have questions about how nginx parses and supports PHP programs. Don't panic, I will write about it in the next article.

The above is the detailed content of Original: Centos 7 source code compilation and installation of Nginx 1.13. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn