Configure multiple domain names and nginx servers for nginx servers
The nginx server supports configuring multiple sites. We can configure sub-domain names to place multiple projects under one domain name.
So how to implement this process?
Many solutions on the Network, some of which are too complicated to write, some of which are misconfigured, or some configuration items must be configured according to the actual environment of the host.
1. Assume that your project path is in the/home/wwwroot/path, and the nginx installation path is in the/usr/local/nginx/directory.
2. After nginx is installed, a default configuration file is available. The file path is/usr/local/nginx/conf/nginx. conf.
3. Now you need to map your project to multiple domain names. First, check the last line of the nginx. conf file. It indicates that all. conf files under the current vhost directory are included. In this case, we can create this folder without a vhost file.
access_log /home/wwwlogs/access.log access; }include vhost/*.conf;
4. Create a domain name configuration file under the vhost directory and name it as custom. Then we can add content to it. The following describes several specific configuration items ).
1. index index.html index. php depends on the location file. If the domain name is directly located, It will be located in the index.html or index. php file.
2. fastcgi_pass: Specifies the fastcgi server interface to which the http proxy is sent.
3. fastcgi_index the file set by this command will be appended to the URI and saved in the variable $ fastcgi_script_name
4. fastcgi_param SCRIPT_FILENAME path of the script file request
5. include fastcgi_params; include all parameters in fastcgi_params
server{ listen 80; server_name www.news.com; root /home/wwwroot/news/; location /{ index index.html index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/tmp/fastcgi.socket; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }}
5. If we are testing on the local machine and set the virtual domain name, how can we access it on our own linux host?
1. We can map the domain name to our host by modifying/etc/hosts. For example, the previously defined www.news.com
2. Open the hosts file and add 127.0.0.1 www.news.com
3. If the hosts file is modified, it is still inaccessible. The network file needs to be modified. Open the/etc/sysconfig/network file, change it to NETWORKING = yes, then the service network restart, and restart the network