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 and configure nginx HTTP server

2025-01-30 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 how to install and configure the nginx HTTP server, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to install and configure the nginx HTTP server. Let's take a look.

Http server

Because tomcat is slow to deal with static resources, the first thing that comes to mind is to put all static resources (js,css,image,swf)

When it comes to separate servers, use a faster http server. Nginx is chosen here. Nginx is lighter than apache.

Configuration is easier, and nginx is not only a high-performance http server, but also a high-performance reverse proxy server.

At present, many large websites use nginx, Sina, NetEase, qq and so on all use nginx, which shows that the stability and performance of nginx are still very good.

1. Nginx installation (linux)

Download the latest stable version

Download the corresponding template according to the functions you need. Here are the following modules:

Openssl-0.9.8l,zlib-1.2.3,pcre-8.00

Compile and install nginx:

. / configure

-- without-http_rewrite_module

-- with-http_ssl_module

-- with-openssl=../../lib/openssl-0.9.8l

-- with-zlib=../../lib/zlib-1.2.3

-- with-pcre=../../lib/pcre-8.00

-- prefix=/usr/local/nginx

Make

Make install

2. Nginx handles the configuration of static resources

# start gzip to compress css and js

Gzip on

# Compression level 1-9. The default is 1. The higher the compression level, the greater the compression rate, and of course, the longer the compression time.

Gzip_comp_level 4

# Compression type

Gzip_types text/css application/x-javascript

# define the service for static resource access, corresponding domain name: res.abc.com

Server {

Listen 80

Server_name res.abc.com

# enable the caching of files read by the server

Open_file_cache max=200 inactive=2h

Open_file_cache_valid 3h

Open_file_cache_errors off

Charset utf-8

# judge that if it is an image or swf, the client will cache it for 5 days

Location * ^. +. (ico | gif | bmp | jpg | jpeg | png | swf) ${

Root / usr/local/resource/

Access_log off

Index index.html index.htm

Expires 5d

}

# due to frequent js,css changes, the client caches for 8 hours

Location ~ * ^. (js | css) ${

Root / usr/local/resource/

Access_log off

Index index.html index.htm

Expires 8h

}

# other static resources

Location / {

Root / usr/local/resource

Access_log off

Expires 8h

}

}

3. Nginx reverse proxy settings

# reverse proxy service, binding domain name www.abc.com

Server {

Listen 80

Server_name www.abc.com

Charset utf-8

# bbs uses discuz!

# for reverse proxy to improve performance, part of the http header information will not be forwarded to the server in the background

# use proxy_pass_header and proxy_set_header to forward the necessary http header information to the backend server

Location ^ ~ / bbs/ {

Root html

Access_log off

Index index.php

# forward the information of host. If you do not set host, the domain name obtained by using request.getservername () in the background is not www.abc.com, but 127.0.0.1

Proxy_set_header host $host

# because of discuz! For security, you need to obtain the client user-agent to determine whether each post data comes from the same browser as the first request

# if you don't forward user-agent,discuz! If you submit the data, you will report the error of "your request is incorrect and cannot be submitted".

Proxy_pass_header user-agent

Proxy_pass http://127.0.0.1:8081;

}

# other requests are forwarded to tomcat

Location / {

Root html

Access_log off

Index index.jsp

Proxy_pass http://127.0.0.1:8080;

}

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

Root html

}

}

This is the end of the article on "how to install and configure the nginx HTTP server". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to install and configure nginx HTTP server". If you want to learn more, you are welcome to follow the industry information channel.

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