How to configure nginx server multi-site
1. First, find the location of the nginx configuration file. The nginx.conf file on Alibaba Cloud is in /alidata/server/nginx-1.4.4/conf.
2. Then create a vhosts directory in the conf directory. This directory is used to store the configuration files of different sites.
3. Then, add a line include /alidata/server/nginx/conf/vhosts/*.conf;
user www www; worker_processes 1; error_log /alidata/log/nginx/error.log crit; pid /alidata/server/nginx/logs/nginx.pid; #specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; log_format '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # 加入下面一行 表示将 vhosts 下面所有的 conf 文件包含进来 include /alidata/server/nginx/conf/vhosts/*.conf; }
4 at the end of nginx.conf. , just write the conf file of your corresponding site in the vhosts directory. An example is given below
server { listen 80; # 这个表示 网站域名, 可以是二级甚至多级域名 server_name localhost demo.com www.demo.com test.demo.com; # 表示默认索引文件 index index.html index.htm index.php; # 该站点对应的网站根目录所在 root /alidata/www/demo; location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } # 伪静态规则 include /alidata/server/nginx/conf/rewrite/phpwind.conf; access_log /alidata/log/nginx/access/phpwind.log; }
5. If you want to continue adding, copy the file directly. Then modify server_name, root, and access_log (if necessary) and it will be ok.
6. Then, do not restart nginx immediately. You should first test whether the nginx configuration file is normal. Find the sbin directory of nginx. Note that this place is the sbin directory of nginx (this directory is the same level as the conf directory of nginx). There are many directories with the same name as sbin under Linux. It's easy to get it wrong. The general default directory on the Alibaba Cloud server is /alidata/server/nginx-1.4.4/sbin.
7. Enter cd /alidata/server/nginx-1.4.4/sbin, and then enter ./nginx -t. If the console displays the following two lines, it means The configuration is successful, otherwise please continue to check the configuration file according to the prompts.
nginx: the configuration file /alidata/server/nginx/conf/nginx.conf syntax is ok
nginx: the configuration file /alidata/server/nginx/conf /nginx.conf test is successful
8. After the configuration is successful, you need to restart the nginx server. Enter the command in the sbin directory: ./nginx -s reload, and then the whole process is completed.
In addition, let’s summarize some common commands of nginx:
Start
./nginx
Restart
./nginx -s reload
Close
ps -ef | grep nginx # 查询nginx主进程号
Easy stop kill -quit main process number
quick stop kill -term main process number
force stop kill - 9 nginx
If nginx.conf is configured with the pid file path, if not, then in the logs directory
kill - signal type'/usr/local/nginx/ logs/nginx.pid'
Judge whether the configuration file is correct
./nginx -t
The above is the detailed content of How to configure nginx server multi-site. 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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

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.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".
