Detailed Aliyun nginx Server multi-site configuration _nginx

Source: Internet
Author: User
Tags nginx server aliyun

Aliyun nginx Server Multi-site configuration

Today configured a number of sites, the process of recording the configuration ...

1, first to find the Nginx configuration file, Ali cloud on the nginx.conf file on the/alidata/server/nginx-1.4.4/conf.

2, then in the Conf directory to create a vhosts directory, which is used to store the different site configuration files.

3, then, in Nginx.conf finally joined a line of include/alidata/server/nginx/conf/vhosts/*.conf;

User www www. 
Worker_processes 1; 
Error_log/alidata/log/nginx/error.log Crit; 
#Specifies the value for maximum file descriptors the can is 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 '; 
# Join the following line to indicate that all the Conf files below Vhosts are included in the include/alidata/server/nginx/conf/vhosts/*.conf; 

4, then, is in the vhosts directory to write your corresponding site of the Conf file. An example is given below

server { 
  listen    ; 
  # This represents the site domain name, can be two or even multi-level domain name 
  server_name localhost; 
  # represents the default index file index 
  index.html index.htm index.php; 
  # the site's corresponding site root directory is located in 
  Location ~. *\. (PHP|PHP5) $ 
    #fastcgi_pass unix:/tmp/php-cgi.sock; 
    Fastcgi_index index.php; 
    Include fastcgi.conf; 
  Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) $ 
    expires 30d; 
  Location ~. *\. (JS|CSS)? $ 
    expires 1h; 
  # pseudo-static rule 

5, if you want to continue to add, copy files directly. Then modify server_name, root, and access_log (if necessary) ok.

6, then, do not immediately restart Nginx, you should first test the Nginx configuration file is normal. Locate the Nginx sbin directory. Note that this is the Nginx sbin directory (this directory is the same as the Nginx conf directory). There are many directories with the same name as Sbin under Linux. Easy to get wrong. The general default directory on the Aliyun server is/alidata/server/nginx-1.4.4/sbin.

7, input Cd/alidata/server/nginx-1.4.4/sbin, and then enter./NGINX-T, if the console displays the following two lines, the configuration is successful, otherwise please continue to check the configuration file as prompted.

Nginx:the configuration file/alidata/server/nginx/conf/nginx.conf syntax is OK

Nginx:configuration file/alidata/server/nginx/conf/nginx.conf Test is successful

8, after the successful configuration, you will need to restart the Nginx server. In the Sbin directory, enter the command:./nginx-s reload, and the whole process is complete.

In addition, summarize several common commands of Nginx:





Shut down

Ps-ef | grep nginx   

Calmly stop kill-quit the main process number

Quick Stop Kill-term The main process number

Force Stop kill-9 Nginx

If nginx.conf configured the PID file path, if not, in the logs directory

Kill-Signal type '/usr/local/nginx/logs/ '

Determine if the configuration file is correct


The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.