LNMP add, delete virtual host

Under normal circumstances, each virtual host is a website, and the website is generally accessed through a domain name. Today we will talk about how to add multiple virtual hosts to a server.

First of all, we need to resolve the domain name; those who do not have a domain name need to buy first

1. First perform domain name resolution. Take Alibaba Cloud as an example. First log in to Alibaba Cloud 

2. Enter the console, find the domain name and website in the right column, click Cloud DNS, the domain name you purchased will be displayed on the right

3. Select the domain name that needs to be resolved, and click the resolution setting behind the change domain name to add resolution to the resolution list.

  

4. Enter the analysis list and click Add Analysis.

  

5. Fill in the domain name you want to resolve and the server IP to resolve to, and click OK.

     

##Add Website (Virtual Hosting)##

If there is an input error and need to be deleted, you can hold down Ctrl and press the Backspace key to delete it.

Execute: lnmp vhost add  The following interface appears:

     

Here you need to enter the domain name of the website you want to add. We have added the www.vpser.net domain name as an example. Enter the domain name www.vpser.net after the prompt in the above picture. After pressing Enter, you will be prompted

     

Here you are asked whether to add more domain names, and directly enter the domain name to be bound. Here we also bind vpser.net, and separate multiple domain names with spaces. If you do not need to bind other domain names, just press Enter.

(Note: Domain names with www and without www are different domain names. If you want to visit the same website with www and without www domain names, you need to bind them at the same time).

The following needs to set the directory of the website

    

The website directory will be created if it does not exist. You can also enter an existing directory or a directory to be set ( note that if you want to enter a full path, that is, a full path starting with /!!! ). If you don't enter the press Enter directly, the default directory is used: /home/wwwroot/domain name

    

Pseudo-static can make the URL more concise and beneficial to SEO. If the program supports it and needs to set pseudo-static, for example, enable input y, do not enable input n and press Enter (note that LNMPA or LAMP mode does not have this option!).

    

By default, there are discuz, discuzx, discuzx2 (Discuz X secondary directory), wordpress, wp2 (WordPress secondary directory), typecho, typecho2 (Typecho secondary directory), sablog, emlog, dabr, phpwind, , dedecms, drupal, The commonly used Nginx pseudo-static configuration files such as ecshop and shopex can be used directly by entering the name. If it is a secondary directory, it needs to correspond to the name of the secondary directory in the configuration file.

    

This step is to set the log, such as enable log input y, not enable input n carriage return.

    

If it is enabled, you need to enter the name of the log to be set. The default log directory is: /home/wwwlogs/ The default file name is: domain name.log After confirming by pressing Enter, it will ask whether to add a database and database user.

    

If you need to add a database, enter y, do not add a database, enter n and press Enter.

    

If you want to add, you need to verify the MySQL root password (Note: Entering the password will not be displayed)
prompts Enter database name: and then enter the database name to be created, the database user name to be created will be the same as the database name, press Enter to confirm.

Prompt Please enter password for mysql user database name: Then enter the password to be set, and press Enter to confirm.

If an FTP server is installed, it will ask whether to add an FTP account

    

When prompted Enter ftp account name:, enter the name of the FTP account to be created, and press Enter to confirm.
Prompt Enter password for ftp account FTP account: Then enter the password to be set, and press Enter to confirm.

Next is the Add SSL feature added in 1.4

    

If you need to add input y, do not add input n and press enter.
If you choose to add SSL, you will be prompted

    

There are two options, 1 option is to use the SSL certificate and key prepared by yourself.

    

> > After prompting Please enter full path to SSL Certificate file, enter the full path and file name of the SSL certificate, and press Enter to confirm.
> > Prompt Please enter full path to SSL Certificate Key file: Then enter the full path and file name of the key file to be entered, and press Enter to confirm.

The 2 option is to use the certificate of the free SSL certificate provider Letsencrypt to automatically generate the SSL certificate and other information.

    

You need to enter an email address to confirm.

After the prompt Press any key to start create virtul host..., press Enter to confirm and the virtual host will be created.

If the addition is successful, it will prompt the added domain name, directory, pseudo-static, log, database, FTP and other related information, as shown below:

   

##Pseudo-static management##

LNMPA or LAMP can directly use .htaccess in the root directory of the website to set pseudo-static rules (for specific rules, you can go to the official website of the program to find google Baidu), but under LNMP, you need to use Nginx pseudo-static rules.
Pseudo-static can be added or deleted at any time. If you forget or do not add pseudo-static after adding virtual hosts, you can add pseudo-static by modifying the configuration file.
The virtual host configuration file is in: /usr/local/nginx/conf/vhost/domain name.conf

The pseudo-static rule file needs to be placed under /usr/local/nginx/conf/.
To edit the virtual host configuration file, you can use vi .

For example, the virtual host we added earlier, the first half of the configuration will be displayed as follows

   

Add the following line in root /home/wwwroot/www.vpser.net;
include wordpress.conf;
the wordpress.conf above is a pseudo-static file. If you need other pseudo-static files, create your own and upload it to /usr/local/ nginx/conf/ and include pseudo-static.conf; after adding and saving, execute: /etc/init.d/nginx restart  restart to take effect, if an error is reported, it may be added incorrectly or the pseudo-static rule is incorrect.

##Upload website program##

If the FTP server has been installed , you can directly use the ftp client to log in through your FTP information to upload the website or sftp and other software to upload the website, set the relevant permissions and start the installation.
After uploading the website, it is recommended to execute: chown www:www -R /path/to/dir to set permissions on the website directory, and replace /path/to/dir with your website directory.
For security, you can remove the execution permission from some directories such as uploaded files that do not require PHP to run, refer to: http://www.vpser.net/security/lnmp-remove-nginx-php-execute.html

##Existing virtual host add ssl certificate to open https##

To add an https site to an existing virtual host, you can execute the lnmp ssl add  command to add an ssl certificate. Currently, there are two ways: one is to use the self-provided ssl certificate, and the other is to use the free certificate from Let'sEncrypt. The addition process is the same as the previous process of adding a virtual host, except that there will be one more step to fill in the ssl certificate and key or directly select Let'sEncrypt to automatically generate a certificate.
If you need to upgrade from 1.* version to 1.4 or change the version, you need to refer to: https://lnmp.org/faq/upgrade1-4.html  for instructions, if there is a prompt that it is not safe or does not display the small green lock, there is also a link above illustrate.

##List Websites (Virtual Hosts)##

Execute: lnmp vhost list

##Delete Website (Virtual Hosting)##

Execute: lnmp vhost del

Deleting a website will first list the existing virtual hosts. Enter the domain name of the virtual host to be deleted as prompted and press Enter to confirm.

This is just to delete the virtual host configuration file, the website file will not be deleted and need to be deleted by yourself.
Under LNMP 1.2, you need to execute: chattr -i /website directory/.user.ini to delete the website directory.

When executing chown or chmod to operate the website directory owner group or permissions, it may prompt chown: changing ownership of `/home/wwwroot/default/.user.ini': Operation not permitted, don't need to pay attention, if there is forced For symptoms, you can refer to the operation of chattr -i first.

##Default Website (Virtual Host)##

LNMP default website configuration files: /usr/local/nginx/conf/nginx.conf
LNMPA default website configuration files: /usr/local/nginx/conf/nginx.conf and /usr/local/apache/conf/extra/httpd- vhosts.conf
LAMP default website configuration file: /usr/local/apache/conf/extra/httpd-vhosts.conf

##Anti-cross directory settings##

LNMP 1.1 and earlier versions use php.ini, and open_basedir is used to set

the anti-cross-directory function of LNMP 1.2 and later versions. Use .user.ini. This file is in the root directory of the website. You can modify the value of open_basedir in .user.ini to Set a restricted access directory or delete to remove the anti-cross-directory setting.

The .user.ini file cannot be directly modified. If you want to repair or delete it, you need to execute: chattr -i /website directory/.user.ini
can be modified using winscp file management , vim editor or nano editor .
If you delete it, rm -f /website directory/.user.ini will do.
After the modification is completed, execute: chattr +i /website directory/.user.ini
.user.ini does not need to be restarted and generally takes effect in about 5 minutes, or you can restart php-fpm to take effect immediately.
If you want to change the website directory, you must modify the anti-cross-directory settings according to the above method, otherwise an error will be reported! !

If you don't want to use anti-cross-directory or modify the anti-cross-directory directory of .user.ini on LNMP 1.4, you need to change the fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/ in /usr/local/nginx/conf/fastcgi.conf" :/proc/"; Add # before the line or delete the line, you need to restart nginx.

On LNMP 1.4, you can also directly use ./remove_open_basedir_restriction.sh in the lnmp1.4/tools/ directory to remove.
Under the frameworks of Thinkphp, codeigniter, Laravel, etc., the website directory is generally under public, but the programs under public need to call files under the public parent directory across directories. Because LNMP does not allow cross-directory access by default, it is necessary to Remove the setting of anti-cross-directory access, and sometimes the 500 error in the program of these framework classes may also be caused by this problem.


The php_admin_value open_basedir parameter in the corresponding apache virtual host configuration file (if the lnmp management tool is added, the file is /usr/local/apache/conf/vhost/domain name.conf) for the anti-cross-directory setting of LNMPA or LAMP mode version 1.2 and above is performed. set up. If you don't need to set it, you can add # to comment, or modify the directory limit yourself.
Restart apache to take effect.

##pathinfo settings##

The settings of each version of pathinfo on LNMP are basically the same:

On lnmp v1.1, modify the configuration file of the corresponding virtual host (/usr/local/nginx/conf/vhost/domain name.conf)
to remove the # in front of #include pathinfo.conf , comment out try_files $uri =404; preceded by #.

On 1.2 and 1.3, modify the configuration file of the corresponding virtual host (/usr/local/nginx/conf/vhost/domain
name.conf) and replace include enable-php.conf; with include enable-php-pathinfo.conf;

modifying pathinfo requires Restart nginx to take effect.

##Database management##

For versions 1.3 and above, you can choose to create a database when adding a virtual host, or you can use lnmp database add alone to add a database as prompted. The added user name and database name have the same name.
Add database command: lnmp database add
Edit database user password Command: lnmp database edit
Delete database command: lnmp database del
List all databases Command: lnmp database list

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325296962&siteId=291194637