Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of experience in using Nginx

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Nginx

Brief introduction of Nginx

A lightweight Web server / reverse proxy server and email (IMAP/POP3) proxy server

Nginx command parameters

Nginx-t tests whether the configuration is correct

Nginx-s reload loads the latest configuration

Nginx-s stop stop immediately

Nginx-s quit elegant stop

Nginx-s reopen reopens the log

Quick restart of kill-USR2 cat / usr/local/nginx/logs/nginx.pid

Nginx global segment configuration

Worker_processes 1; the worker process is 1 CPU * core

Events segment Nic request 80443 Nginx trigger event

Nginx configure virtual host

Listen

Server_name

Location

Nginx log management

* system default log format: log_format main'$remote_addr $request_length $body_bytes_sent $request_ time [s]-- [$time_local]''"$request" $status $http_referer "-" $http_user_agent "$server_name $server_addr $http_x_forwarded_for $http_x_real_ip'

* Custom log format: log_format simple'$remote_addr-- $request'

* system default log definition: remote IP- remote user / user time request method request body length referer source information http-user-agent user agent / spider the original ip http_x_forwarded_for of the forwarded request when the agent adds your original IP to this header message and transmits your original IP

Nginx-Laravel5 project building

Window upload local project use secureCRT-sftp put get command to upload connect sftp session, remote: cd local: lcd,lpwd, put * .zip

Laravel5 returned 500permission modification: 1.chmod 777-R storage 2.chmod 777-R bootstrap/cache/

Configure env: vi .env modify database configuration related parameters

Execute php artisan migrate to create a data table

Nginx supports pathinfo

# typical configuration location ~\. Php$ {root html; fastcgi_pass 127.0.0.1 root html; fastcgi_pass 9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name; include fastcgi_params;} # modify lines 1 and 6 to support pathinfolocation ~\ .php (. *) ${# regular matching of pathinfo part root html; fastcgi_pass 127.0.0.1 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME 9000; fastcgi_index index.php Fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name; fastcgi_param PATH_INFO $1; # assign the pathinfo part to the PATH_INFO variable include fastcgi_params;}

Nginx supports URL rewriting

1. If it is not a resource file, rewrite it.

If (!-e $request_filename) {rewrite (. *) $/ index.php/$1;}

2.try_files

Try_files $uri $uri/ / index.php?$args

Nginx reverse proxy and static and dynamic separation

Use Nginx as a reverse proxy using proxy_pass. Take a reverse proxy as an example. Nginx does not process the request for the picture itself, but forwards the request for the picture to Apache for processing.

Location ~\. (jpg | jpeg | png | gif) ${proxy_pass HTTP://IP:port;}

Reverse proxy causes the back-end server to connect to the client IP as the front-end server IP instead of the real IP solution

Location ~\. (jpg | jpeg | png | gif) {proxy_set_header X-Forwarded-For $remote_addr; proxy_pass IP:port;}

Nginx Cluster and load balancing

The Upstream {} module joins multiple servers into a group and then memcache pass, fastcgi_pass, proxy_pass = > upstream group

Configure Upstream

Upstream web {server IP:8080 weight=1 max_fails=2 fail_timeout=30s; server IP2:80 weight=1 max_fails=2 fail_timeout=30s;}

Downstream call

Location ~\. (jpg | png | gif | jpeg) {proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://web;}

Interpretation of Common policies for load balancing

Load balancing based on cookie values (Nginx sticky modules)

Using consistent hash algorithm to do equalization based on URI (NginxHttpUPstreamConsistentHash module)

Load balancing based on IP

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report