Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install Nginx for Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to install Nginx in Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Environment required for installation

Nginx is a C language development, it is recommended to run on Linux, of course, you can also install the Windows version, note: this article uses CentOS 7 as the installation environment.

one。 Gcc installation

To install nginx, you need to compile the source code downloaded from the official website. The compilation depends on the gcc environment. If there is no gcc environment, you need to install:

Yum install gcc-c++

two。 PCRE pcre-devel installation

PCRE (Perl Compatible Regular Expressions) is a Perl library, including a perl-compatible library of regular expressions. Nginx's http module uses pcre to parse regular expressions, so you need to install the pcre library on linux. Pcre-devel is a secondary development library developed using pcre. This library is also required for nginx. Command:

Yum install-y pcre pcre-devel

three。 Zlib installation

The zlib library provides many ways to compress and decompress. Nginx uses zlib to gzip the contents of the http package, so you need to install the zlib library on Centos.

Yum install-y zlib zlib-devel

four。 OpenSSL installation

OpenSSL is a powerful secure socket layer cipher library that includes major cryptographic algorithms, commonly used key and certificate encapsulation management functions, and SSL protocols, and provides rich applications for testing or other purposes.

Nginx supports not only the http protocol, but also https (that is, http over the ssl protocol), so you need to install the OpenSSL library on Centos.

Yum install-y openssl openssl-devel

Download from the official website

1. Download the .tar.gz installation package directly at https://nginx.org/en/download.html

two。 Download using the wget command (recommended).

Wget-c https://nginx.org/download/nginx-1.10.1.tar.gz

Decompression

It's still a direct order:

Tar-zxvf nginx-1.10.1.tar.gz

Cd nginx-1.10.1

Configuration

In fact, in the nginx-1.10.1 version, you don't need to configure related things, just default. Of course, it's OK if you want to configure the directory yourself.

1. Use default configuration

. / configure

Note: to specify the temporary file directory as / var/temp/nginx, you need to create temp and nginx directories under / var

Compilation and installation

Make

Make install

Find the installation path:

Whereis nginx

Start and stop nginx

Cd / usr/local/nginx/sbin/

. / nginx

. / nginx-s stop

. / nginx-s quit

. / nginx-s reload

. / nginx-s quit: in this way, the stop step is to stop after the nginx process has finished processing the task.

. / nginx-s stop: this method is equivalent to finding out the nginx process id and then using the kill command to force the killing of the process.

Query the nginx process:

Ps aux | grep nginx

Restart nginx

1. Stop and then start (recommended):

Restarting nginx is equivalent to stopping and then starting, that is, executing the stop command before the startup command. As follows:

. / nginx-s quit

. / nginx

two。 Reload the configuration file:

When nginx's configuration file nginx.conf is modified, you need to restart nginx for the configuration to take effect. You can use-s reload to take effect in nginx without first stopping nginx and then starting nginx, as shown below:

. / nginx-s reload

After launching successfully, you can see a page like this when the browser visits the local IP:

Boot self-start

That is, add the startup code to rc.local.

Vi / etc/rc.local

Add one line / usr/local/nginx/sbin/nginx

Set execution permissions:

Chmod 755 rc.local

This is the end of the content of "how to install Nginx in Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report