How to configure common functions after Nginx installation
1. Separation of the main configuration file and the virtual host
If there are many virtual hosts, it will be more convenient to separate them. They can also be divided according to functions and services. The following takes two virtual hosts as an example.
Complete configuration file after removing blank lines and comments:
[root@nginx-01 conf]# egrep -v "#|^$" nginx.conf.bak worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
Create the virtual host configuration directory under the /app/nginx/conf directory
mkdir extra
Use the server module to create www and bbs two virtual sites
[root@nginx-01 conf]# cat -n nginx.conf [root@nginx-01 conf]# sed -n '10,20p' nginx.conf server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
www site
[root@nginx-01 conf]# cat extra/www.conf server { listen 80; server_name www.yygg.com; location / { root html/www; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
bbs site
[root@nginx-01 conf]# cat extra/bbs.conf server { listen 80; server_name bbs.yygg.com; location / { root html/bbs; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html/bbs; } }
Main configuration file configuration (nginx.conf)
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include extra/www.conf; include extra/bbs.conf; }
Check configuration
[root@nginx-01 conf]# /app/nginx/sbin/nginx -t nginx: the configuration file /app/nginx-1.18.0//conf/nginx.conf syntax is ok nginx: configuration file /app/nginx-1.18.0//conf/nginx.conf test is successful
Create the site directory
[root@nginx-01 conf]# mkdir /app/nginx/html/{www,bbs} [root@nginx-01 conf]# echo "http://www.yygg.com" >>/app/nginx/html/www/index.html [root@nginx-01 conf]# echo "http://bbs.yygg.com" >>/app/nginx/html/bbs/index.html [root@nginx-01 conf]# echo "192.168.1.5 www.yygg.com bbs.yygg.com" >>/etc/hosts
Start the service and test
[root@nginx-01 conf]# /app/nginx/sbin/nginx [root@nginx-01 conf]# curl www.yygg.com http://www.yygg.com [root@nginx-01 conf]# curl bbs.yygg.com http://bbs.yygg.com
2. Virtual host alias setting
Take the www site as an example, set the alias
The so-called alias is to set one or more additional domain names
in addition to the main domain name to www.yygg.com
and set an alias yygg.com
.
[root@nginx-01 conf]# cat extra/www.conf server { listen 80; server_name www.yygg.com yygg.com; location / { root html/www; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html/www; } }
Restart nginx test
[root@nginx-01 conf]# /app/nginx/sbin/nginx -s reload [root@nginx-01 conf]# cat /etc/hosts 192.168.1.5 www.yygg.com bbs.yygg.com yygg.com [root@nginx-01 conf]# curl yygg.com http://www.yygg.com
3.Nginx status status information configuration
Status information recording is implemented using the `ngx_http_stub_status_module` module
Input/app/nginx/sbin/nginx -V
Check whether the above module is included in the compilation:
nginx version: nginx/1.18.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --user=nginx --group=nginx --prefix=/app/nginx-1.18.0/ --with-http_stub_status_module --with-http_ssl_module
Create a status virtual host, refer to title 1 for the method, status.conf
Configuration The file is as follows:
server { listen 80; server_name status.yygg.com; location / { stub_status on; access_log off; } }
Main configuration filenginx.conf
Append status virtual host configuration
sed -i '11 i include extra/status.conf;' nginx.conf
Check the syntax and restart nginx
/app/nginx/sbin/nginx -t /app/nginx/sbin/nginx -s reload
Configure hosts resolution
192.168.1.5 status.yygg.com
Visit status.yygg.com
View
[root@nginx-01 conf]# curl status.yygg.com Active connections: 1 server accepts handled requests 4 4 4 Reading: 0 Writing: 1 Waiting: 0
Display result analysis:
Active connections: 1 ##The number of connections being processed is 1
server ##A total of 4 connections have been processed
accepts ##A total of 4 handshakes have been created
handled requests ##A total of 4 processes have been processed Requests
Reading ##The number of Header information read to the client
Writing ##The number of Header information returned to the client
Waiting ##NGinx has finished processing the resident connection that is waiting for the next request command Number
4. Add error log
error_log syntax:
error_log file level;
keyword remains unchanged , file is the log storage location, level is the error log level
Usually only three levels of warn|error|crit are used
Configure the error log configuration in nging.conf
In the file, add
underworker_processes 1;
Yes, this is the line!
The above is the detailed content of How to configure common functions after Nginx installation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To allow the Tomcat server to access the external network, you need to: modify the Tomcat configuration file to allow external connections. Add a firewall rule to allow access to the Tomcat server port. Create a DNS record pointing the domain name to the Tomcat server public IP. Optional: Use a reverse proxy to improve security and performance. Optional: Set up HTTPS for increased security.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

To solve the "Welcome to nginx!" error, you need to check the virtual host configuration, enable the virtual host, reload Nginx, if the virtual host configuration file cannot be found, create a default page and reload Nginx, then the error message will disappear and the website will be normal show.

There are five methods for container communication in the Docker environment: shared network, Docker Compose, network proxy, shared volume, and message queue. Depending on your isolation and security needs, choose the most appropriate communication method, such as leveraging Docker Compose to simplify connections or using a network proxy to increase isolation.

To register for phpMyAdmin, you need to first create a MySQL user and grant permissions to it, then download, install and configure phpMyAdmin, and finally log in to phpMyAdmin to manage the database.

Server deployment steps for a Node.js project: Prepare the deployment environment: obtain server access, install Node.js, set up a Git repository. Build the application: Use npm run build to generate deployable code and dependencies. Upload code to the server: via Git or File Transfer Protocol. Install dependencies: SSH into the server and use npm install to install application dependencies. Start the application: Use a command such as node index.js to start the application, or use a process manager such as pm2. Configure a reverse proxy (optional): Use a reverse proxy such as Nginx or Apache to route traffic to your application

Converting an HTML file to a URL requires a web server, which involves the following steps: Obtain a web server. Set up a web server. Upload HTML file. Create a domain name. Route the request.

Troubleshooting steps for failed phpMyAdmin installation: Check system requirements (PHP version, MySQL version, web server); enable PHP extensions (mysqli, pdo_mysql, mbstring, token_get_all); check configuration file settings (host, port, username, password); Check file permissions (directory ownership, file permissions); check firewall settings (whitelist web server ports); view error logs (/var/log/apache2/error.log or /var/log/nginx/error.log); seek Technical support (phpMyAdmin
