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!