Linux operation and maintenance of personal blog sites Mount

Temporarily turn off the firewall

Here Insert Picture Description

Permanently turn off the firewall
Here Insert Picture Description

By accessing linux text pages

Here Insert Picture Description

Nginx Rewrite

1. What is the rewrite

That URL Rewrite rewrite, the main achievement url address rewriting and redirection is to redirect incoming Web request to another URL process.

2.Rewrite usage scenarios

1.URL jump address, such as user access to jump to old.com new.com , or when the user access via http hs.com, to jump to the https access hs.com
2.URL pseudo-static, dynamic pages will be displayed as a technique for static pages the way for easy entry of search engines, while reducing dynamic URL address of external exposure to too many parameters to enhance the higher security.
3. Search engine optimization SEO relies on URL path, in order to support the search engine entry.
4. You can adjust the URL users to browse, it seems more standardized, in line with demand and product development personnel.

Prevent malicious IP resolution

server {
listen 80 default_server;
return 302 http://www.hs.com;
}

server {
listen 80;
server_name www.hs.com;
location / {
return 302 https:// s e r v e r n a m e server_name REQUEST_URI;
}
}

LNMP to build applications and
the role of LNMP
LNMP is Nginx + MySQL + + Linux PHP,
Linux as the operating system of the server
Nginx as a Web server
PHP dynamic scripting language parsing as
MySQL is the database

Nginx PHP service itself can not handle the request, then the request when a user initiates a dynamic PHP, Nginx and how is it treated.
There are two methods:
1. PHP page resolution request forwarded to the processing Apache
2. forwards the resolution request to the PHP page module php-fpm *****
User -> HTTP protocol -> Nginx-> fastcgi protocol -> php-fpm

Note: fastcgi protocol is connected between nginx php-fpm.

1. User initiated by the http protocol request, the request will first arrive LNMP architecture Nginx
2.Nginx will be judged according to the user's request, the judge is carried out to complete the Location
3. judgment requested by the user is a static page, Nginx directly processed
4. Analyzing dynamic page is requested by the user, Nginx will send the request to the protocol fastcgi
5.fastgi php-fpm will request to the management process, the worker thread calls the specific wrapper php-fpm management process after receiving
6.wrapper threads call php is parsed, if only parsing code php directly back
7. If you have a query database operations, connected by php database (user password IP) then initiates an action query
8. final data from the mysql-> php- > php-fpm-> fastcgi-> nginx- > http-> user

#########

1. Install Nginx
# 1. Rpm package using Nginx official offer
slightly
################################### #############
2. install the MySQL
primitive steps:
1. Download the MySQL official extended source

rpm -ivh http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-release-el7-5.noarch.rpm

2. Install mysql5.6, the file is too large may result in slow downloads

yum install mysql-community-server -y

Training steps:
1. mysql56.tar.gz xshell transmitted by the server

mkdir /soft

cd /soft

2. Extract

tar xf mysql56.tar.gz

3. Install mysql56 (yum repository is required)

mount /dev/cdrom /mnt

yum install -y mysql5.6/*

3. Start the database and add boot from the start
[root @ nginx ~] # systemctl Start mysqld
[root @ nginx ~] # systemctl enable mysqld

# 4. Since mysql5.6 root of the default administrator password is blank, the server starts, you can log in directly
[root @ web01 ~] # MySQL-uroot-
......
MySQL>

# 5. For safety, you must set a password for root

mysqladmin -u root password 123.com

If you already have a password, modify again

mysqladmin -uroot -p123.com -password 123

# 6. Use password mysql

mysql -uroot -p123.com


mysql>

Note: mysql is absolutely no source installation, all functions are achieved by modifying the configuration file.

####################

3. The use of third-party extensions source mounting php7.1
original step:
# 1 remove the old php (php preceded by mounting Base epel library or off, this operation must be performed)

yum remove php-mysql-5.4 php php-fpm php-common

# 2. Installation extended source

yum localinstall -y http://mirror.webtatic.com/yum/el7/webtatic-release.rpm

# 3. Installation php7.1 version

yum -y install php71w php71w-cli php71w-common php71w-devel \

php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm
php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb

Training steps:
# 1 php71.tar.gz transmitted by the server xshell

mkdir /soft

cd /soft

# 2. Unzip

tar xf php71.tar.gz

# 3. Installation php7.1

yum install -y php7.1/*

# 4. Start php-fpm management process, and adding boot from Kai

systemctl start php-fpm

systemctl enable php-fpm

Check whether to open ports 9000

ss -lntp | grep: 9000

#################
Verify Nginx can properly resolve php dynamic requests, and php program can connect to your database
1. Create a test site

vim /etc/nginx/conf.d/www.conf

server {
server_name www.hs.com;
listen 80;

location / {
	root /code/www;
	index index.php index.html;
}

location ~ \.php$ {
    root /code/www;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

}

2. Add info.php, the test is working properly parse php

vim /code/www/test.php

<?php phpinfo(); ?>

3. Test whether php mysql database service can connect [whether it is consistent with the local database or remote database, test mode]

vim /code/www/mysql.php

<?php $servername = "localhost"; $username = "root"; $password = "123.com"; // 创建连接 $conn = mysqli_connect($servername, $username, $password); // 检测连接 if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo "连接成功"; ?>

LNMP environment to build
1. Make sure the yum repository is available, it is recommended to use the local CD realization

mount /dev/cdorm /mnt

rm -rf /etc/yum.repos.d/*

vim /etc/yum.repos.d/cdrom.repo

[cdrom]
name=cdrom repo
baseurl=file:///mnt
enabled=1
gpgcheck=0

yum repolist

2. Create / soft, store all the required training software

mkdir /soft

cd /soft

Use xshell or xftp will spread to all of the software under / soft directory

3. Install the software LNMP

cd /soft

tar xf mysql56.tar.gz

tar xf php71.tar.gz

Yum localinstall -y nginx-1.16.0-1.el7.ngx.x86_64.rpm mysql5.6 / * php7.1 / *

Here Insert Picture Description

Here Insert Picture Description

4. Start mysql

systemctl start mysqld

systemctl enable mysqld

5. Modify the root password mysql administrator

mysqladmin -u root password 123.com

6. Start php-fpm

systemctl start php-fpm

systemctl enable php-fpm

7. Modify the www site configuration file, add support for php

vim /etc/nginx/conf.d/www.conf

server {
server_name www.hs.com;
listen 80;

location / {
root /code/www;
index index.php index.html;
}

location ~ \.php$ {
    root /code/www;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

}

Here Insert Picture Description

8. Restart nginx

systemctl restart nginx

9. Create a test page, test LNMP architecture build success

vim /code/www/test.php

<?php phpinfo(); ?>

vim /code/www/mysql.php

<?php $servername = "localhost"; $username = "root"; $password = "123.com"; // 创建连接 $conn = mysqli_connect($servername, $username, $password); // 检测连接 if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo "连接成功"; ?>

10. Client Access test page with a browser
http://www.hs.com/test.php
http://www.hs.com/mysql.php

Here Insert Picture Description

Here Insert Picture Description

LNMP Application 2: blog
1. Download the source code wordpress
2. Unzip the source code

cd /soft

unzip wordpress-4.9.4-zh_CN.zip

3. All the contents in the extracted directory copy or cut to the specified directory site

cp -r wordpress/* /code/blog/

or

mv wordpress/* /code/blog/

4. Create the required database

mysql -uroot -p123.com

mysql> create database wordpress;
mysql> exit

5. Modify permissions
1) modify your site directory, nginx let users write access (upload)

chown -R nginx /code/blog

2) Modify php-fpm user program nginx

sed -i ‘s#apache#nginx#’ /etc/php-fpm.d/www.conf

6. Modify blog site configuration file, add support php page parsing

vim /etc/nginx/conf.d/blog.conf

server {
……
location / {
root /code/blog;
index index.php index.html;
}

location ~ \.php$ {
    root /code/blog;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

}

7. Restart nginx and php-fpm

systemctl restart nginx php-fpm

8. http://bbs.hs.com access through a browser, the page prompts to complete the installation

Modify permission
to change the file permissions

Change the permissions php

Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description

wecenter mount step, most of the steps similar to the above blog

Here Insert Picture Description

Change the target of all rights

Here Insert Picture Description

Experimental results

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_43254438/article/details/93761593