Linux nginx
Nginx是一个⚒️轻量级/高性能的反向代理Web🗄️服务器,它是由C语言写的,所以速度非常快、性能非常优秀。
📦️安装
apt install nginx -y
安装成功后的目录:/etc/nginx
配置文件:/etc/nginx/nginx.conf
日志文件:/var/log/nignx
🏷️配置模板
以halo为例
user www-data;
# worker_processes auto;
worker_processes 2;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
##
# Gzip Settings
##
gzip on;
gzip_min_length 15k;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 9;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
upstream halo {
server 127.0.0.1:8090;
}
server {
listen 80;
# listen 443 ssl;
server_name uain.cc;
if ($host != 'uain.cc'){
return 403;
}
# ssl_certificate xxxxxxx.pem绝对路径;
# ssl_certificate_key xxxxxxxx.key绝对路径;
location / {
proxy_pass http://halo;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 1024m;
}
}
}
🔖相关指令
nginx
启动😀
nginx -s stop
关闭😅
nginx -s quit
等待用户请求的处理后关闭主进程🙃
nginx -t
查看配置文件是否正确🙂
nginx -s reopen
重新打开日志文件😉
nginx -s reload
重新启动😄
nginx -c <config>
使用指定的配置文件🤗