nginx -t
查看nginx的配置文件是否语法正确
which nginx
rpm -ql nginx
查看nginx的位置
可以双server段进行配置,设置不同的server段限制
server {
listen 8001;
listen [::]:8001;
server_name localhost;
charset utf-8;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 8000;
listen [::]:8000;
server_name minio.com;
client_max_body_size 100M;
client_body_buffer_size 1M;
location / {
proxy_pass http://localhost:8002;
}
#location /login {
server {
listen 9100;
listen [::]:91;
server_name mysql.com;
client_max_body_size 100M;
client_body_buffer_size 1M;
location / {
proxy_pass http://localhost:<port>;
}
# need requests
location /login {
proxy_pass http://localhost:<port>/<endpoint>;
}
location /datamanager {
proxy_pass http://localhost:<port>/<endpoint>;
}
location /download/ {
alias /data/share;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
nginx 配置文件可以设置多个后台接口
注: 后台可以设置多个转发,endpoint可以配置django的URL 模块进行设置,作为WSGI服务器进行配合
#### jenkins配置
location /jenkins {
proxy_pass http://localhost:8010;
#proxy_pass http://localhost:8080; # Jenkins默认运行在8080端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
#### http段落优化
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
# keepalive_timeout 65;
# types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 连接头优化
keepalive_timeout 75s;
keepalive_requests 10000;
types_hash_max_size 2048;
server_tokens off; # 隐藏版本号
# 缓冲区配置
client_body_buffer_size 16k;
client_header_buffer_size 2k;
large_client_header_buffers 4 8k;
# 超时设置
send_timeout 20s;
client_header_timeout 20s;
client_body_timeout 20s;
# worker_cpu_affinity 0001 0010 0100 1000;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
# 重启nginx配置
nginx -t
nginx -t -c /path/to/nginx.conf
sudo systemctl reload nginx
sudo nginx -s reload
sudo kill -HUP $(cat /run/nginx.pid)
systemctl status nginx # 查看服务状态
ps -ef | grep nginx # 确认新旧进程共存
curl -I http://localhost # 测试服务响应
sudo systemctl revert nginx # 回滚至上次有效配置
nginx配置加载
动态加载模块
也可以回滚配置,通过
systemctl revert nginx
检查这个目录是否可以访问
sudo -u nginx ls -ld /data/share