Install nginx on Alibaba Cloud server in linux environment and access web pages through nginx

Note: Nginx feels very convenient after personal use, so here is the installation and configuration plan for yourself. It is a high-performance Web and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Load balancing is a good choice.

My linux server is CentOS 7.4 64 bit of Alibaba Cloud, the following is the installation process

Step 1: Install PCRE pcre-devel and Zlib first, these two things will be used when configuring nginx

1. PCRE (Perl Compatible Regular Expressions) is a Perl library, including Perl compatible regular expression library. The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on linux. pcre-devel is a secondary development library developed using pcre.

Nginx also needs this library. command:

	yum install -y pcre pcre-devel

Insert picture description here

2. The zlib library provides many ways to compress and decompress. nginx uses zlib to gzip the contents of the http package, so you need to install the zlib library on Centos.

yum install -y zlib zlib-devel

Insert picture description here3. After installing these two, you can install nginx, but if there is a problem during installation, you may need to install GCC and OpenSSL. The following commands are provided

yum install gcc-c++
yum install -y openssl openssl-devel

Step 2: Install nginx, 1.14.0

	wget -c https://nginx.org/download/nginx-1.14.0.tar.gz

1. Unzip and enter the nginx directory

	tar -zxvf nginx-1.14.0.tar.gz
	cd nginx-1.14.0

2. Use nginx's default configuration

	./configure

3. Compile and install

	make
	make install

4. Find the installation path:

	whereis nginx

Insert picture description here

5. Enter the sbin directory, you can see that there is an executable file nginx, just execute ./ and it will be OK.

After running, visit the server ip, you can see the welcome page of nginx

Insert picture description here

Insert picture description here

*Here are some points to note

Cannot access the page after installation and startup

1. Check if nginx is installed

	ps -ef|grep nginx

Insert picture description here

If there is a nginx process as shown in the figure above, it means that it has been started. At this time, if you still cannot access the nginx page

2. Check if the security group policy of your server has enabled port 80

The following figure shows that it is turned on

Insert picture description here
3. If you still cannot access after enabling it, you need to check the nginx configuration file nginx.conf

a. Find your own nginx installation directory first

	whereis nginx

Insert picture description here
b. The directory is in /usr/local/nginx, enter the sbin folder and find an executable file of nginx

c. You can execute the following statement in sbin to query where you are using nginx.conf, and this statement can also verify whether your nginx.conf file is correct. The correct format will prompt test is successful

	./nginx -t

Insert picture description here
d. Find the configuration file directory under /usr/local/nginx/conf

e. We edit the mapping path inside. If you need to use domain name access, you need to configure server_name with your own domain name

	server {
	    listen 80 ;# 监听本机所有 ip 上的 80 端口
	    server_name _  ;# 域名:www.example.com 这里 "_" 代表获取匹配所有
	    root /usr/local/nginx/template;# 站点根目录
	    index index.html;
	}

f. This path is the file storage path configured by nginx

 /usr/local/nginx/template/index.html

In this case, there is basically no problem, and you can talk about other issues and discuss them together.

Finally, some basic commands of nginx, some of which have been mentioned before, and are also listed here

start up

Startup code format: nginx installation directory address -c nginx configuration file address

	/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

There are three ways to stop nginx

Calmly stop

	ps -ef|grep nginx

Insert picture description here
Kill process

	kill -QUIT 3905

Quick stop

	kill -TERM 3905

or

	kill -INT 3905

Forced stop

	pkill -9 nginx

Reboot

Method 1: Enter the nginx executable directory sbin and enter the command ./nginx -s reload.
Insert picture description here
Method 2: Find the current nginx process number, and then enter the command: kill -HUP process number to restart
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43945983/article/details/109780979