search
HomeOperation and MaintenanceNginxAnalysis of Nginx installation examples in Linux

Use the system binary source method to install

On the ubuntu/debian system

sudo apt-get install nginx

or the redhat/centos system

sudo yum install nginx

The method is the simplest and fastest way, but it is not the best way. Let’s talk about this main problem below.

Advantages

  • All installation binary dependencies have been processed, no need to worry about compatibility issues, it can be used out of the box

  • You don’t need to deal with the connection configuration and user permissions of nginx, we have already written this for you

  • Don’t worry about nginx bug maintenance and upgrade issues, just get the latest system directly That’s it

  • Uninstallation is simple, just one command

  • Simple log maintenance, automatically truncate the day’s log, compress and save

Disadvantages

  • Cannot choose the installed version

  • Cannot choose the compiled module independently

  • Extended functions become very troublesome and need to be recompiled

  • The directory structure is complex, the configuration file is under /etc/, and the deployment file is under /var/www

  • Restarting the service and modifying the configuration require root permissions

  • Performance is slightly worse Compile and install

If you are a Linux newbie, it is definitely recommended to use this method of installation. You don’t need to consider compilation dependencies. You can use it directly after installation. But if your server is used in a production environment and is being developed and gradually improved, this method is not recommended. Third-party modules may be added in the future, and they must be compiled and installed at that time (discussed below). When restarting the server, do not use the root user, but use sudo to briefly gain root. If your server is used to deploy some static files, mainly for some web spaces, and usually uses the ftp tool to deploy files, there is definitely no problem with this method.

Compile and install

I won’t write about the advantages and disadvantages. Basically, just reverse the above. To install using this method, you must know a little knowledge about Linux compilation, and only moderate Linux users can control it. I saw that most tutorials on the Internet install the compilation dependencies directly in /usr/local/. This method is not good. If we want to uninstall these dependencies in the future, we will find it very troublesome. You can't just delete it directly under the category. Some Linux distributions will write the installation files into the configuration files. I don't know where to find these configuration files. If a dependent version affects other software, how to deal with version issues. We just wanted to install nginx, but it caused a lot of problems.

Compilation environment preparation

Before you start, make sure your Linux is prepared with gcc, make, wget, g software.

Create a category to store downloaded files, enter the directory to download the dependent library source files

Downloading openssl is mainly used for ssl module encryption and supports https

wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz

Download pcre to implement support for address redirection, address rewriting functions, localtion instructions and regular expressions

wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

Download zlib gzip compression module

wget https://zlib.net/zlib-1.2.11.tar.gz

Download nginx

wget http://nginx.org/download/nginx-1.17.1.tar.gz

Use tar to decompress all files

ls *.tar.gz | xargs -n1 tar xzvf

Compilation options

Use ./configure to set various nginx parameter scripts, including the paths to source and configuration files , compiler options, linkage handling methods and module lists. The script does this by creating the makefiles required to compile the code and install nginx open source.

参数 描述
–prefix= nginx安装目录,以及有其他配置脚本选项的路径设置的所有相对路径的基本位置。默认值/usr/local/nginx
–sbin-path=nginx二进制执行文件的名称,默认值:/sbin/nginx</prefix> </td></path> </td></tr> <tr> <td>–conf-path=<path></path> </td> <td>nginx配置文件的名称。但是,您可以通过在nginx命令行上使用选项指定其他文件来始终在启动时覆盖此值。默认值:<prefix> conf / nginx.conf-c <filename></filename></prefix> </td> </tr> <tr> <td>–pid-path=<path></path> </td> <td>nginx.pid文件的名称,用于存储nginx主进程的进程id 。安装后,可以使用nginx配置文件中的pid指令更改文件名的路径。默认值:<prefix> /logs/nginx.pid</prefix> </td> </tr> <tr> <td>–error-log-path=<path></path> </td> <td>error,warn和诊断数据的日志文件的名称。安装后,可以使用nginx配置文件中的error_log指令更改文件名。默认值:<prefix> /logs/error.log</prefix> </td> </tr> <tr> <td>–http-log-path=<path></path> </td> <td>http服务器请求的主日志文件的名称。安装后,始终可以使用nginx配置文件中的access_log指令更改文件名。默认值:<prefix> /logs/access.log</prefix> </td> </tr> <tr> <td>–user=<name></name> </td> <td>nginx运行进程的拥有者。安装后,可以使用nginx配置文件中的user指令更改名称。默认:nobody</td> </tr> <tr> <td>–group=name</td> <td>nginx运行进程的拥有者用户组。安装后,可以使用nginx配置文件中的user指令更改名称。默认值:–user选项设置的值</td> </tr> <tr> <td>–with-pcre=<path></path> </td> <td>pcre库源代码的路径,这是位置指令和rewrite模块中正则表达式支持所必需的</td> </tr> <tr> <td>–with-pcre-jit</td> <td>使用“即时编译”支持(pcre_jit指令)构建pcre库</td> </tr> <tr> <td>–with-zlib=<path></path> </td> <td>zlib库的源代码路径,gzip模块需要该路径</td> </tr> <tr> <td>–with-http_ssl_modul</td> <td>启用https支持</td> </tr> <tr> <td>–with-http_v2_module</td> <td>开启 http/2请求支持</td> </tr> </tbody> </table> <p>还要太多编译参数我就不一一列举,有兴趣的同学可以自己去<br></p> <p>参看</p> <p>编译安装<br></p><pre class='brush:php;toolbar:false;'>./configure \ --with-openssl=../openssl-1.0.2s \ --with-pcre=../pcre-8.43 \ --with-zlib=../zlib-1.2.11 \ --with-pcre-jit --user=admin \ --prefix=/home/admin/nginx \ --with-http_ssl_module \ --with-http_v2_module

输出以下信息,说明依赖没问题

configuration summary
 + using pcre library: ../pcre-8.43
 + using openssl library: ../openssl-1.0.2s
 + using zlib library: ../zlib-1.2.11
 
 nginx path prefix: "/home/admin/nginx"
 nginx binary file: "/home/admin/nginx/sbin/nginx"
 nginx modules path: "/home/admin/nginx/modules"
 nginx configuration prefix: "/home/admin/nginx/conf"
 nginx configuration file: "/home/admin/nginx/conf/nginx.conf"
 nginx pid file: "/home/admin/nginx/logs/nginx.pid"
 nginx error log file: "/home/admin/nginx/logs/error.log"
 nginx http access log file: "/home/admin/nginx/logs/access.log"
 nginx http client request body temporary files: "client_body_temp"
 nginx http proxy temporary files: "proxy_temp"
 nginx http fastcgi temporary files: "fastcgi_temp"
 nginx http uwsgi temporary files: "uwsgi_temp"
 nginx http scgi temporary files: "scgi_temp"

编译

make

安装

make install

设置权限

因为linux设置普通用户,不能占用1024一下的端口,直接启动nginx会出现权限不足的错误。将nginx分配给root用户,在分配特殊权限。

sudo chown root nginx
sudo chmod u+s nginx

The above is the detailed content of Analysis of Nginx installation examples in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

How to start nginxHow to start nginxApr 14, 2025 pm 01:06 PM

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to check whether nginx is startedHow to check whether nginx is startedApr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to close nginxHow to close nginxApr 14, 2025 pm 01:00 PM

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure nginx in WindowsHow to configure nginx in WindowsApr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor