nginx installation and deployment

nginx installation

1. Pre install sudo Yum install Yum utils
2. Create a / etc in the root directory of the server/ yum.repos .d/ nginx.repo File, edit as follows:

    name=nginx stable repo

    name=nginx mainline repo


sudo yum install nginx

In this way, we have completed the installation of nginx. There is no reason why the three steps are required by the official website;
In this way, we install nginx in / etc/nginx/default.conf Medium configuration

2.nginx configuration

The default configuration of nginx we just generated is as follows

user  nginx; //Default user
worker_processes  1;//cpu core

error_log  /var/log/nginx/error.log warn;//Print error log path
pid        /var/run/;//After nginx runs and starts, this identification file will be generated to record the ID number of the main process of nginx.
events {//Set the maximum number of connections
    worker_connections  1024;

http {
    include       /etc/nginx/mime.types; //Set up various types
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';//How to print the log, $identifies the variable

    access_log  /var/log/nginx/access.log  main;//Print access log

    sendfile        on;//Specifies whether sendfile system calls are used to transfer files. Sendfile system calls directly transfer data between two file descriptors (operate entirely in the kernel), so as to avoid copying data between kernel buffer and user buffer. The operation efficiency is very high, which is called zero copy
    keepalive_timeout  65;//Default connection time
   include /etc/nginx/conf.d/*.conf;//The default configuration is contained in the. conf file

The last line above is also clear to us. Let's take a look at the detailed notes of the default configuration:

server {
    listen       80;//Default listening port 80
    server_name  localhost;
    access_log  /var/log/nginx/host.access.log  main;//Print log location
    location / {
        root   /usr/share/nginx/html;//Configure access folders
        index  index.html index.htm;//Configure access path


Download xshell and winscp. Xshell is a tool for connecting to the server. Winscp uploads files to the server, but I have a problem;
First of all, I bought a server from Alibaba cloud server, and then installed and built it according to the above operations. But I changed the configuration file on nginx and it didn't take effect. Because I was the first time to contact nginx and didn't know much about this, I directly used localhost to access it (I'm really an nt, since I uploaded it to the server, of course, I used the server to access it) , but still stay in welcome to nginx! This is a very evil way. Then, it's not a configuration problem to check all kinds of data on the Internet. It's the port we wrote in the configuration file that points to 80, but alicloud needs to set up a security group. After setting, enter the server address in the web address to see what we've changed index.html , but I point to the root file in congf Clipped index.html

 location / {
        root   /root;//Configure access folders
        index  index.html index.htm;//Configure access path

Open the webpage again to display 403. It's OK that I have Baidu. Then I found out that it's a permission problem. Just change the user in the configuration to user nginx. Then restart nginx (restart as long as you change the configuration file), so that you can display the file normally;

Common commands

systemctl start nginx //start nginx 
systemctl status nginx.service  //View the status of nginx
systemctl disable firewalld.service  //Turn off firewall
ps -ef |grep nginx//View process
history  !(No)//History of using commands
systemctl restart nginx.service//Restart nginx

Tags: Web Server Nginx yum sudo CentOS

Posted on Sun, 07 Jun 2020 23:47:24 -0400 by NoReason