nginx configuration, reverse proxy, load balancing

Nginx Common Operations (Linux Environment)

You need to enter the current directory of the nginx file
to view the version number

./nginx -v

end process

./nginx -s stop

reload process

./nginx -s reload

Configuration file:


The nginx configuration file is the nginx.conf global block in the conf directory

events block

http block

http global block

server block

Partial demonstration example configuration

server
    {
    
    
        #监听的端口
        listen 888;                            
        #域名(如果上面有listen,这个就没什么用了)
        server_name phpmyadmin;                
        #客户端通过域名访问服务器时会将域名与被解析的ip一同放在请求中。
        #当请求到了nginx中时。nginx会先去匹配p,如果listen中没有找
        #到对应的ip,就会通过域名进行匹配,匹配成功以后,再匹配端口。
        #当这三步完成,就会找到对应的server的location对应的资源
        index index.html index.htm index.php;
        root  /www/server/php/dist;

        #error_page   404   /404.html;
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
    
     
        #表示缓存时间,在浏览器端缓存时间。减缓服务器的压力
            expires      30d;          
        }

        location ~ .*\.(js|css)?$
        {
    
    
            expires      12h;
        }

        location ~ /\.
        {
    
    
            deny all;
        }

        access_log  /www/wwwlogs/access.log;
    }

location directive and configuration

#~ 区分大小写的正则, ~* 不区分大小的正则
location ~ /edu/ {
    
        
   
}

reverse proxy

recommended article

load balancing

recommended article

After the server is deployed, nginx is started, but the port cannot be accessed

The first step is to configure the firewall on port 888:

firewall-cmd --zone=public --add-port=80/tcp --permanent

The second step is to restart the firewall service:

systemctl restart firewalld.service
or
sudo firewall-cmd --reload

Guess you like

Origin blog.csdn.net/qq_45859670/article/details/123075984