search
HomeOperation and MaintenanceNginxHow 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.

How to configure nginx server multi-site

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

How to configure nginx server multi-site

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!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Using NGINX Unit: Deploying and Managing ApplicationsUsing NGINX Unit: Deploying and Managing ApplicationsApr 22, 2025 am 12:06 AM

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX vs. Apache: A Comparative Analysis of Web ServersNGINX vs. Apache: A Comparative Analysis of Web ServersApr 21, 2025 am 12:08 AM

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINX Unit's Advantages: Flexibility and PerformanceNGINX Unit's Advantages: Flexibility and PerformanceApr 20, 2025 am 12:07 AM

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX vs. Apache: Performance, Scalability, and EfficiencyNGINX vs. Apache: Performance, Scalability, and EfficiencyApr 19, 2025 am 12:05 AM

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

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

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment