Home Operation and Maintenance Nginx How to install and configure nginx under Linux

How to install and configure nginx under Linux

May 23, 2023 pm 11:22 PM
linux nginx

1. Install and configure nginx under Linux

When installing nginx for the first time, any problems that arise in the process will be solved step by step.

The tool securecrt is used to connect and log in to the server.

1.1 rz command, a dialog box will pop up, select the nginx compressed package to be uploaded.

#rz
Copy after login

1.2 Unzip

[root@vw010001135067 ~]# cd /usr/local/
[root@vw010001135067 local]# tar -zvxf nginx-1.10.2.tar.gz
Copy after login

1.3 Enter the nginx folder and execute the ./configure command

[root@vw010001135067 local]# cd nginx-1.10.2
[root@vw010001135067 nginx-1.10.2]# ./configure
Copy after login

The error is reported as follows:

checking for os
 + linux 2.6.32-431.el6.x86_64 x86_64
checking for c compiler ... not found

./configure: error: c compiler cc is not found
Copy after login

This error occurs. Then the gcc package is not installed.

1.3.1 Install gcc

View gcc

[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc:
Copy after login

Install gcc

[root@vw010001135067 nginx-1.10.2]# yum -y install gcc
Copy after login

Check again after successful installation

[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
Copy after login

gcc is installed .

1.3.2 Continue executing ./configure

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for os
 + linux 2.6.32-431.el6.x86_64 x86_64
checking for c compiler ... found
......
checking for pcre library ... not found
checking for pcre library in /usr/local/ ... not found
checking for pcre library in /usr/include/pcre/ ... not found
checking for pcre library in /usr/pkg/ ... not found
checking for pcre library in /opt/local/ ... not found

./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.
Copy after login

The above error occurs. Install pcre-devel

[root@vw010001135067 nginx-1.10.2]# yum install pcre-devel
Copy after login

1.3.3 Execute ./configure again

error: the http gzip module requires the zlib library.
you can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
Copy after login

If there is this error, then execute it

yum install zlib-devel
Copy after login

1.3.4 No error is reported after executing ./configure

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for os
 + linux 2.6.32-431.el6.x86_64 x86_64
checking for c compiler ... found
 + using gnu c compiler
 + gcc version: 4.4.7 20120313 (red hat 4.4.7-17) (gcc) 
.......
configuration summary
 + using system pcre library
 + openssl library is not used
 + md5: using system crypto library
 + sha1: using system crypto library
 + using system zlib library

 nginx path prefix: "/usr/local/nginx"
 nginx binary file: "/usr/local/nginx/sbin/nginx"
 nginx modules path: "/usr/local/nginx/modules"
 nginx configuration prefix: "/usr/local/nginx/conf"
 nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
 nginx pid file: "/usr/local/nginx/logs/nginx.pid"
 nginx error log file: "/usr/local/nginx/logs/error.log"
 nginx http access log file: "/usr/local/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"
Copy after login

1.4 If you want to use openssl function, sha1 function. Then install openssl, sha1

[root@vw010001135067 nginx-1.10.2]# yum install openssl openssl-devel 
[root@vw010001135067 nginx-1.10.2]# install perl-digest-sha1.x86_64
Copy after login

1.4.1 Enable the ssl module and execute ./configure –with-http_ssl_module

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_ssl_module
Copy after login

1.4.2 Enable the “server status” page and execute ./configure –with -http_stub_status_module

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module
Copy after login

You can start the above two commands at the same time

Copy the code The code is as follows:


[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module --with-http_ssl_module

1.5 The above configure passed

Execute the make command, execute the make install command

[root@vw010001135067 nginx-1.10.2]# make
[root@vw010001135067 nginx-1.10.2]# make install
Copy after login

At this point, nginx executes Success

1.6 Configure environment variables

Add configuration to /etc/profile

Open configuration file

[root@vw010001135067 nginx-1.10.2]# vi /etc/profile
Copy after login

Add to configuration file

#nginx configure
export nginx_home=/usr/local/nginx-1.10.2
export path=$path:$nginx_home/sbin
Copy after login

I started to fill it in as above, but it couldn’t be found when using nginx -v. Noticed that the address of my nginx_home configuration above is wrong. First find the installation address of nginx

[root@vw010001135067 nginx-1.10.2]# whereis nginx
nginx: /usr/local/nginx
Copy after login

It’s really the wrong address. Change the above to

#nginx configure
export nginx_home=/usr/local/nginx
export path=$path:$nginx_home/sbin
Copy after login

After compiling, save and exit and execute

[root@vw010001135067 nginx-1.10.2]# source /etc/profile
Copy after login

to make the configuration effective.

1.7 Check nginx version

[root@vw010001135067 nginx]# nginx -v
nginx version: nginx/1.10.2
Copy after login

The whole process was successful!

2. Modify nginx.conf

2.1 Start nginx

My nginx service is at http://10.1.135.67/, after the configuration is successful , now start nginx

[root@vw010001135067 nginx]# cd /usr/local/nginx
[root@vw010001135067 nginx]# nginx -c conf/nginx.conf
Copy after login

The startup is successful, open http://10.1.135.67/ in the browser, the default port number is 80.

How to install and configure nginx under Linux

As shown above, nginx is already working normally.

2.2 Configure tomcat service

Now my tomcat service is at 10.1.29.15 and needs to be forwarded through nginx. Then open nginx.conf and modify the configuration file. As follows, add:

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid  logs/nginx.pid;


events {
 worker_connections 1024;#最大连接数,默认为512
 accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
 multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
 #use epoll;  #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport 
}


http {
 #文件扩展名与文件类型映射表
 include  mime.types;

 #默认文件类型,默认为text/plain 
 default_type application/octet-stream;

 #自定义格式
 log_format main &#39;$remote_addr - $remote_user [$time_local] "$request" &#39;
      &#39;$status $body_bytes_sent "$http_referer" &#39;
      &#39;"$http_user_agent" "$http_x_forwarded_for"&#39;; 

 #combined为日志格式的默认值
 access_log logs/access.log main;

 #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块
 sendfile  on;
 sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。

 #tcp_nopush  on;

 #连接超时时间,默认为75s,可以在http,server,location块。
 keepalive_timeout 65;

 #gzip on;

 upstream upload {
  server 10.1.29.15:8080;
 }

 error_page 404 https://www.baidu.com; #错误页

 server {
  keepalive_requests 120; #单连接请求上限次数。
  listen  80; #监听端口
  server_name localhost; #监听地址 

  #charset koi8-r;

  #access_log logs/host.access.log main;

  location ~ ^.*?/upload/[^/]*?$ {
   proxy_connect_timeout 15;
   proxy_send_timeout 15;
   proxy_read_timeout 15;
   proxy_set_header host $host;
   proxy_set_header x-real-ip $remote_addr;
   proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
   proxy_set_header connection "";
   proxy_pass http://upload; #请求转向upload 定义的服务器列表
   client_max_body_size 1024m;
} 
 }
}
Copy after login

After configuration, save the configuration file and restart nginx

[root@vw010001135067 nginx]# nginx -s reload
Copy after login

Whether the upload project is called successfully in the browser

How to install and configure nginx under Linux

As shown in the figure, the project can be accessed correctly and the configuration is successful!

The above is the detailed content of How to install and configure nginx under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

How to install deepseek How to install deepseek Feb 19, 2025 pm 05:48 PM

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

Ouyi okx installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Get the gate.io installation package for free Get the gate.io installation package for free Feb 21, 2025 pm 08:21 PM

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi Exchange Download Official Portal Ouyi Exchange Download Official Portal Feb 21, 2025 pm 07:51 PM

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

See all articles