search
HomeOperation and MaintenanceNginxHow to install and configure nginx HTTP server

http server
Because tomcat processes static resources slowly, the first thing that comes to mind is to mention all static resources (js, css, image, swf)
to a separate server , use a faster http server, here we choose nginx. Compared with apache, nginx is more lightweight,
configuration is simpler, and nginx is not only a high-performance http server, but also a high-performance reverse proxy server .
Currently, many large websites use nginx. Sina, NetEase, QQ, etc. 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
First 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. Configuration of nginx processing of static resources
#Start gzip Compress css and js
gzip on;
# Compression level 1-9, the default is 1, the higher the level, the greater the compression rate, of course, the longer the compression time
gzip_comp_level 4;
# Compression Type
gzip_types text/css application/x-javascript;
# Defines the service for static resource access, corresponding domain name: res.abc.com
server {
listen 80;
server_name res .abc.com;
# Turn on the cache 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;
# Determine if it is a picture or swf, the client caches 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 and 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, bind domain name www.abc.com
server {
listen 80;
server_name www.abc.com;
charset utf-8;
# bbs uses discuz!
# In order to improve the performance of the reverse proxy, part of the http header information will not be forwarded to the background server.
# Use proxy_pass_header and proxy_set_header to Forward the required http header information to the backend server
location ^~ /bbs/ {
root html;
access_log off;
index index.php;
# Forward host information, if Without setting the 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 is used to determine whether each post data comes from the same browser as the first request.
# If user-agent is not forwarded, discuz! will report "The source of your request is incorrect and cannot be submitted" when submitting the data. Submit "
proxy_pass_header user-agent;
proxy_pass http://127.0.0.1:8081;
}
# Forward other requests 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;
}
}

The above is the detailed content of How to install and configure nginx HTTP server. 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
How to solve nginx encounter ddosHow to solve nginx encounter ddosApr 14, 2025 pm 12:12 PM

Nginx's DDoS attacks can be dealt with by identifying attack types, mitigating attacks, protecting Nginx configuration, monitoring and response, and working with service providers. Specific steps include enabling rate limiting, using WAF and CDN, updating Nginx, encrypting with TLS/SSL, monitoring logs, establishing an alert system, developing a contingency plan, and contacting a hosting provider and reporting to the authorities.

How to deploy jar program in nginxHow to deploy jar program in nginxApr 14, 2025 pm 12:09 PM

To deploy a JAR program on Nginx, seven steps need to be followed: 1) Install JRE, 2) Install Nginx, 3) Configure Nginx, 4) Deploy JAR, 5) Grant execution permissions, 6) Restart Nginx, 7) Verify deployment.

How to solve nginx current limitHow to solve nginx current limitApr 14, 2025 pm 12:06 PM

The Nginx current limit problem can be solved by: use ngx_http_limit_req_module to limit the number of requests; use ngx_http_limit_conn_module to limit the number of connections; use third-party modules (ngx_http_limit_connections_module, ngx_http_limit_rate_module, ngx_http_access_module) to implement more current limit policies; use cloud services (Cloudflare, Google Cloud Rate Limiting, AWS WAF) to DD

How to check status of nginxHow to check status of nginxApr 14, 2025 pm 12:03 PM

There are several ways to check Nginx status: Use the Nginx Status module to view the real-time status. Use command line tools (nginx -V, nginx -t, service nginx status/systemctl status nginx) to check version, configuration, and service status. Check the log file (/var/log/nginx/error.log) for running status information.

How to distinguish multiple domain names from nginxHow to distinguish multiple domain names from nginxApr 14, 2025 pm 12:00 PM

Multiple domain names can be distinguished by configuring nginx server block: Specify a unique server_name directive for each domain name. Repeat the above steps to create multiple server blocks. If the requested domain name does not match any server block, nginx will use the default server block for processing.

How to check nginx versionHow to check nginx versionApr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to see if nginx is startedHow to see if nginx is startedApr 14, 2025 am 11:54 AM

To see if Nginx is started, use the following steps: Check the status with the systemctl command: systemctl status nginx Check the configuration and see if Nginx is running: nginx -t Check whether Nginx listens to port 80: netstat -plnt | grep nginx

How to start php server in nginxHow to start php server in nginxApr 14, 2025 am 11:51 AM

Nginx starts the PHP server through FastCGI or PHP-FPM. The specific steps include: installing the FastCGI module and configuring the Nginx configuration file, and specifying the location of the PHP-FPM socket file. Install and configure PHP-FPM, set up listening socket files and start PHP-FPM. Add the proxy pass configuration in the Nginx configuration file to forward the PHP request to the PHP-FPM server (usually 127.0.0.1:9000). Start Nginx and test access to the PHP file to verify that the PHP server is started.

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development 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.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment