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

The method of installing and configuring nginx under Linux

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "the method of installing and configuring nginx under Linux". The editor shows you the operation process through the actual case. The method of operation is simple, fast and practical. I hope that this article "the method of installing and configuring nginx under Linux" can help you solve the problem.

1. Install and configure nginx under linux

When you install nginx for the first time, the problems that arise in the middle are solved step by step.

Use the tool securecrt to connect and log in to the server.

1.1 rz command, a dialog box pops up to select the nginx package to upload.

# rz

1.2 decompression

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

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

The error is as follows:

Checking for os + linux 2.6.32-431.el6.x86_64 x86_64checking for c compiler... Not found./configure: error: c compiler cc is not found

This error occurred. So the gcc package is not installed.

1.3.1 install gcc

View gcc

[root@vw010001135067 nginx-1.10.2] # whereis gccgcc:

Install gcc

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

Check again after successful installation

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

Gcc is installed.

1.3.2 continue to execute. / configure

[root@vw010001135067 nginx-1.10.2] #. / configurechecking for os + linux 2.6.32-431.el6.x86_64 x86_64checking for c compiler... Found.checking for pcre library... Not foundchecking for pcre library in / usr/local/... Not foundchecking for pcre library in / usr/include/pcre/... Not foundchecking for pcre library in / usr/pkg/... Not foundchecking 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_moduleoption, or install the pcre library into the system, or build the pcre librarystatically from the source with nginx by using-with-pcre= option.

There was an error like the above. Install pcre-devel

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

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_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using-with-zlib= option.

If there is this error, then execute it.

Yum install zlib-devel

1.3.4 No error was reported after the execution of. / configure

[root@vw010001135067 nginx-1.10.2] #. / configurechecking for os + linux 2.6.32-431.el6.x86_64 x86_64checking 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"

1.4 if you want to use the openssl function, the sha1 function. Then install openssl and sha1.

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

1.4.1 Open ssl module execution. / configure-with-http_ssl_module

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

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

The above two commands can be started at the same time

The copy 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 make command, execute make install command

[root@vw010001135067 nginx-1.10.2] # make [root@vw010001135067 nginx-1.10.2] # make install

At this point, the nginx execution has been successful.

1.6 configure environment variables

Add configuration to / etc/profile

Open the configuration file

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

Add to the configuration file

# nginx configureexport nginx_home=/usr/local/nginx-1.10.2export path=$path:$nginx_home/sbin

I started to fill it out like above, but I couldn't find it when I nginx-v. Notice that the address configured by my nginx_home above is not correct. First find the installation address of nginx

[root@vw010001135067 nginx-1.10.2] # whereis nginxnginx: / usr/local/nginx

I really wrote the wrong address. Change the one on it to

# nginx configureexport nginx_home=/usr/local/nginxexport path=$path:$nginx_home/sbin

Save exit and execute after compilation

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

Make the configuration effective.

1.7 View nginx version

[root@vw010001135067 nginx] # nginx-vnginx version: nginx/1.10.2

The whole process worked!

2. Modify nginx.conf

2.1 start nginx

My nginx service is in http://10.1.135.67/. After the configuration is successful, start nginx now.

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

Launch successfully, open http://10.1.135.67/ in the browser, the default port number is 80.

As shown in the picture above, nginx is already working properly.

2.2 configure the 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. Add as follows:

# user nobody;worker_processes 1% error 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 switch # maximum number of connections. Default is 512 accept_mutex on; # to set network connection serialization to prevent clustering. Default is on multi_accept on; # to set whether a process accepts multiple network connections at the same time. Default is off # use epoll # event-driven model, select | poll | kqueue | epoll | resig | / dev/poll | eventport} http {# File extension and File Type Mapping Table include mime.types; # default file type, default is text/plain default_type application/octet-stream; # Custom format log_format main'$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"'"$http_user_agent"$http_x_forwarded_for"' # combined is the default value of log format access_log logs/access.log main; # allows files to be transferred by sendfile, default is off, you can transfer files in http block, server block and location block sendfile on; sendfile_max_chunk 100k. # the number of transfers per call per process cannot be greater than the set value, and the default is 0, that is, there is no upper limit. # tcp_nopush on; # connection timeout. The default is 75s, which can be found in the http,server,location block. Keepalive_timeout 65; # gzip on; upstream upload {server 10.1.29.15 gzip on; upstream upload 8080;} error_page 404 https://www.baidu.com; # error page server {keepalive_requests 120; # maximum number of single connection requests. Listen 80; # listening port server_name localhost; # listening address # 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; # request to go to upload defined server list client_max_body_size 1024m;}

Once configured, save the configuration file and restart nginx

[root@vw010001135067 nginx] # nginx-s reload

Whether the call to the upload project in the browser is successful

If the picture can access the project correctly, the configuration is successful!

This is the end of the introduction on "how to install and configure nginx under Linux". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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