nginx new site on linux

Encountered a problem of stripping off some of the background modules and putting them back on a new background;

In this way, it is necessary to create a new site on the server, but the server is a linux system, and I am not very familiar with it. After many efforts, it was done.

Record here, the linux command used, the software uses Xshell5;

First, connect to the cloud server remotely (well, let you know that you are using Alibaba Cloud):

First, use the cd command to find the nginx configuration file, or use the vi command to open the file, usually the file /etc/nginx/nginx.conf

See no, the nginx.conf configuration file is really here, open it with the vi command below

Since the arrow below is the content of this file, let's look at some of the fields:

This host configuration tells us that this nginx will go to the following two places to read the site configuration information, then, since we are the background before the assignment, let's go to the previous background site configuration file;

After reading the file, what should I do if I want to exit? Here we look at the content of the file through vi, then to exit, use the following command:

Press the Esc key of the keyboard, and then enter " :q! Enter " in turn. 
The clear point is the colon, the letter q, the exclamation mark, and the Enter key.

That's it, back to the previous interface, then how to find the configuration file of the previous site, I only vaguely remember that the site is called my.tao or something, so what to do next

ok, I saw what I wanted to see, yes, the previous site configuration file is in the sites-enabled folder of the current directory (etc/nginx), then I will find this file and copy it

cp a.conf b.conf, this command is to copy the a file in the current folder to the b file in the current folder (the b file does not need to exist in advance)

In addition to copying the site configuration file, also copy the background folder of the previous site, the command is:

cp -r app1/* app2/ ------------------------ The meaning of this command is to copy all the files under the app1 folder under the current folder file, copy it to the app2 folder of the current directory

Then, I will not paste the copy of the background folder. After the file is copied, it is the DNS resolution of the domain name. This is resolved on Alibaba Cloud, and the domain name is resolved to the server IP.

Suppose, after I have resolved lian.taobao***.com to the IP address of the current server, we can change the previously copied lian.taobao***.com.conf

First open the configuration file with the vi command:

The red arrow is the place we want to change, press the i key on the keyboard, --INSERT-- will appear in the lower left, and you can move the cursor to the specified Difan to modify it;

After modification, Esc + : + wq + Enter (save and exit)    Esc + : + q! + Enter (do not save and exit);

At this point, you also need to execute nginx -s reload to restart the nginx server. At this point, you can enter lian.taobao***.com on the browser to access the site on your server, the specified root directory;

By default, the index.* file in the root directory will be accessed (in the above example, it is to access the /var/www/html/code/yii2/lian/web/index.* file under the current server )

 

Notice:

When copying background files, if you manually create a new folder on Xftp and copy the background files to this folder, there will be a permission problem, like the following:

Have you seen the attributes of these folders? The default attribute is 755, the permissions are not enough, and some write operations cannot be executed, and an error that cannot be written will be reported.

Then we can type the following code: chmod -R 777 lian   The meaning of this sentence is: let the lian folder and its sub-files/folders in the current directory set 777 permissions, that is, everyone can read and write

In this way, there will no longer be a folder permission problem and an error will be reported when the background file is to be written.

 

Finally, summarize all the linux commands used:

cd /etc/nginx                    // Go to the nginx directory 
cd ..                            // Return to the previous directory, note that there is a space after cd 
vi /etc/nginx/nginx.conf         // Open the nginx.conf file Esc- 
>:q !                        // After opening the file, return to the previous interface 
i                                // After opening the file, switch to the editing state 
Esc-> :wq                        // After editing the file, save and exit 
Esc-> :q!                        // After editing the file, do not save and exit 
gerp - R ' my '                     // Find (sub)files/folders whose names contain 'my' in the current directory 
cp -r app1 /* app2/               //Copy all files/folders in the app folder to the current directory under the app2 folder
rm -r app                        //Delete the app folder in the current directory
 chmod -R 777 lian                //Set 777 permissions for the specified folder and its subfolders/folders in the current directory
 nginx -s reload                  //Restart nginx

 

Guess you like

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