Recently, taking advantage of the discount of Double 11, we changed the server manufacturer and reconfigured the new server. Record the configuration process

This document applies to CentOS 7.x.

First you have to have a server

Buy a good server, specific operations because of the different server manufacturers, not the same

If configured, small site 1G 1 core is done, more prices also follow up.

Pick out the configuration, order and pay. The cloud server is ready, through SSH command link in the terminal, you can already enter the server

How to use SSH connection, Baidu know.

Here does not say how the server link, how to buy, how to land… I would like to introduce some things that I can do on a server

Initial configuration

One: Change the password

Log in to the host as user root, so change the password of root first. It is recommended to generate a complex password with a tool like password generator. Then, memorizing the password is not going to be possible in your protected memo, or in your notebook. Please keep your own password.

The command is

passwd
Copy the code

After entering the command there will be a prompt, follow the prompt to step down

2: Create a user

There may be more than one user maintenance of their website, so you need to set up a user for yourself

useradd -d /home/roy -s /bin/bash -m roy
Copy the code

In the preceding command, d specifies the user’s home directory, s specifies the user’s shell, and m indicates that the directory will be created if it does not exist.

The next step is to set the password for the new user

passwd roy
Copy the code

Once the password is set, the new user is granted permission

visudo
Copy the code

The visudo command opens the sudo setup file /etc/sudoers and finds the following line

root    ALL=(ALL:ALL) ALL
Copy the code

Add a line below this line

roy     ALL=(ALL:ALL) ALL
Copy the code

After saving the changes, you can exit the current root login and log in as the newly created user to see if it is successful

Three: SSH Settings

In fact, every time through SSH login, need to enter the password I think it is ok, not very troublesome. At least some sense of security. However, you can copy the SSH public key of your local machine into the authorized_keys file on your server

cat ~/.ssh/id_rsa.pub | ssh [email protected] 'mkdir -p .ssh && cat - >> ~/.ssh/authorized_keys'

Or on the server side, run the following command

echo "ssh-rsa [your public key]" > ~/.ssh/authorized_keys
Copy the code

Then modify the default SSH configuration on some servers by editing the SSH configuration file /etc/ssh/sshd_config

sudo cp /etc/ssh/sshd_config ~
sudo nano /etc/ssh/sshd_config
Copy the code

Enter the file and you will see the default configuration for Port 22, which can be changed to whatever Port you like (any integer between 1025 and 65536) to ensure that it does not conflict with other ports.

Personally feel that modify a port number is enough, if you need other configuration can baidu.

Finally, after saving the changes, restart SSH. If there are no problems, the changes should have taken effect after the restart. You can use exit to check whether the configured port number works

If it is convenient, you can create a config file in the ~/.ssh folder on your machine and write the following contents in it

Please fill in the content after the # and delete the #
Host # The name you want to give this server
HostName IP address of the server
User # username
Port The default port number is 22
Copy the code

Once you’ve saved it, try SSH’s name for the server to see if you can successfully log in

At this point, I for their own server preliminary configuration content is over, this part is mainly reference and extract Ruan Yifeng teacher Linux server preliminary configuration process main content, thank you, delete.

Nginx installation and simple configuration

The site is usually built with an LNMP on the server, but I’m using Hexo to build a static site, so I don’t need MySql, PHP or anything like that. You only need to install and configure Nginx, so here’s how. You can search for LNMP configurations

The installation

Add an RPM package for installation

# add Nginx package
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

# installation
sudo yum -y install nginx
Copy the code

Just wait for it to download, and then a message will ask you if you want to install it. Type Yes and press Enter

Once installed, you are ready to start Nginx

# start service
sudo systemctl start nginx
# if the server fails to start, it may be Apache or other services that occupy port 80.

# Set nginx to boot
sudo systemctl enable nginx
Copy the code

The default nginx port is 80, so if another service occupies port 80 on the server, nginx will fail to start

It is worth mentioning that some hosts will set up some default security groups (which can be seen in the console of the host vendor), then even if the port 80 on the server is ok, the host security group is not configured with 80, it will also lead to failure to access, so the failure to access the situation can be identified one by one

To test whether the installation is successful, enter the IP address of the server in the browser address bar. If the following information is displayed, the installation is successful

{% asset_img nginx-test-page.png nginx-test-page %}

configuration

This is just a brief mention of the configuration, which should be covered in the next and next article (Flag), as well as some of the web optimization that comes with configuration

I am directly modifying the global configuration file /etc/nginx/nginx.conf

The main thing is to change the root entry to the path of my website project

vim /etc/nginx/nginx.conf
Copy the code
server {
    listen 80;
    #... The default configuration is omitted
    root /home/www;
    #... The default configuration is omitted
    #...
    location / {
    	index index.html index.htm;
    }
    #...
}
Copy the code

These are just examples

After saving the changes, you can use the nginx -t command to test whether the configuration file is correct. If ok is displayed, the configuration change is successful. Systemctl restart nginx systemctl restart nginx

The last

So far, that’s all I want to document in this article, just a relatively simple initial server configuration and nginx installation configuration. This paper has no specific teaching purpose and effect. Just some of the things that authors do to keep track of when they buy a new server. In fact, the configuration of the server Baidu will have a lot of good tutorials, you can need their own Baidu

reference

The initial configuration process of the Linux server

4, Nginx installation & configuration

Centos7 Restart the apache, nginx, mysql, and php-fpm commands

Author: Roy Luo

Link to this article: Simple Site setup – preliminary configuration