linux回炉第二十八天
原创
©著作权归作者所有:来自51CTO博客作者大雨小柚子的原创作品,请联系作者获取转载授权,否则将追究法律责任
请求报文:
方法:URL:版本
首部字段:值
curl -v www.jd.com
响应报文:
版本:状态码:短语
首部字段:值
curl -H "name: wang" www.dayu.com -v
cat /proc/sys/fs/file-max
nginx -V
nginx -t
nginx -s reload
nginx -s stop
systemctl start nginx
systemctl stop nginx
workr_processes auto;
#worker_cpu_affinity auto;
worker_cpu_affinity 0001 0010;
worker_rlimit_nofile 65536; 配合etc/security/limit.conf 里的nofile使用
daemon off; #dockerfile必须关闭后台执行
全局main
event {
}
http {
}
mail{
}
stream {
}
server {
listen 80;
server_name www.wang.org;
root /data/nginx/html;
location / {
index index.html;
}
}
server {
listen 80;
server_name www.wang.org;
root /data/www;
location {
index index.html;
}
location /test {
alias /mnt/test;
}
error_page 404 @@error_404;
location @@error_404 {
default_type text/html;
charset utf8;
return 200 '您访问的页面走丢了!';
}
deny 11.0.1.1;
allow 11.0.1.0/24;
deny all;
}
server {
listen 80;
server_name www.wang.org;
root /data/www;
location / {
index index.html;
}
location /admin {
auth_basic "please input your user and passwd";
auth_basic_user_file /opt/user.txt;
}
}
htpasswd -c -b /opt/user.txt wang 123456
htpasswd -b /opt/user.txt li 123456
server {
listen 80;
server_name www.wang.org;
root /data/www;
error_page 404 /data/www/error/404.html;
location / {
index index.html;
}
}
server {
listen 80;
server_name www.li.org;
root /data/www;
error_page 404 =200 /index.html;
location / {
index index.html;
}
}
server {
listen 80;
server_name www.wang.com;
error_log /data/www/wang.com-error.log;
try_files $uri $uri/index.html $url.html =489;
root /data/www;
location / {
index index.html;
}
}
autoindex on;
autoindex_format html;
autoindex_format json;
limit_rate 100k;
limit_rate 100m;
core
access
auth_basic
sub_status
gzip
ssl
rewrite
proxy
stream
upstream
fastcgi
referer
log
mail
limit_req_zone $binary_remote_addr zone=test:10m rate=1r/s;
server {
......
limit_req zone=test burst=10 nodelay;
......
}
limit_conn_zone $binary_remote_addr zone=conn_zone:10m;
server {
......
limit_conn conn_zone=2;
......
}
server {
listen 80;
server_name www.wang.org;
root /data/www;
location /status {
stub_status;
}
}
curl -s http://www.wang.org/status | awk 'NR==3{print $3}'
server {
......
gzip on;
gzip_comp_level 5;
gzip_min_length 1k;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/gif image/png;
gzip_vary on;
......
}
server {
listen 443 ssl http2;
server_name www.wang.org;
root /data/www;
ssl_certificate /etc/nginx/cert/www.wang.org.crt;
ssl_certificate_key /etc/nginx/cert/www.wang.org.key;
location / {
index index.html;
}
}
apt install libnginx-mod-http-echo
server {
listen 8080;
server_name www.li.org;
root /data/www;
location /hahaha {
index index.html;
default_type text/html;
root /mnt/test;
if (!-e $request_filename) {
echo "$request_filename is not exist";
}
}
}
server {
listen 8080;
server_name www.li.org;
root /data/www;
location /test {
if ($scheme = http){
return 301 http://www.wang.org;
}
}
}
server {
listen 80;
server_name www.wang.org;
root /data/www;
location / {
return https://www.wang.org;
}
}
server {
listen 443 ssl http2;
server_name www.wang.org;
ssl_certificate /etc/nginx/cert/www.wang.org.crt;
ssl_certificate_key /etc/nginx/cert/www.wang.org.key;
root /data/www;
location / {
index index.html;
}
}
server {
listen 8080;
server_name www.li.org;
root /data/www;
location /test {
if ($scheme = http){
return 301 https://www.li.org;
}
}
}
server {
listen 8080;
server_name www.li.org;
root /data/www;
return 302 https://$server_name$request_uri;
}
}
server {
listen 80;
server_name www.wang.org;
root /data/www;
location / {
rewrite /index.html http://www.baidu.com redirect;
}
}
server {
listen 8080;
server_name www.li.org;
root /data/www;
location / {
rewrite /index.html http://www.baidu.com permanent;
}
}
server {
listen 80;
server_name www.wang.org;
root /data/www;
location / {
rewrite /index.html http://www.baidu.com redirect;
}
}
server {
listen 80;
server_name www.wang.org;
root /data/www;
location / {
rewrite .* /index.html redirect;
}
}
server {
listen 8080;
server_name www.li.org;
root /data/www;
location / {
rewrite .* http://www.wang.org/index.html permanent;
}
}
vim /etc/nginx/nginx.conf
http {
......
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" "$http_x_forwarded_for"';
......
}
server {
listen 8080;
server_name www.li.org;
root /data/www;
access_log /data/www/li.org_access.log main;
location / {
index index.html;
}
}
# 防盗链
server {
listen 8080;
server_name www.li.org;
root /data/www;
access_log /data/www/li.org_access.log main;
location /images {
index index.html;
valid_referers none blocked server_names
m.li.org ~\.google\. ~\.baidu\.;
if ($invalid_referer){
return 403;
}
}
}
server {
listen 80;
server_name www.eryou.org;
root /data/www;
location / {
# proxy_pass http://11.0.1.58;
proxy_pass http://www.test.org;
proxy_set_header Host $http_host;
}
}
server {
listen 80;
server_name www.eryou.org;
root /data/www;
location ~* \.php$ {
proxy_pass http://www.test.org;
proxy_set_header Host $http_host;
}
}
server {
listen 8888;
server_name www.li.org;
root /data/www;
access_log /data/www/li.org_access.log main;
location / {
proxy_pass http://11.0.1.58;
proxy_set_header Host $http_host;
add_header X-Via $server_addr;
add_header X-Cache $upstream_cache_status;
add_header X-Accel $server_name;
}
}
upstream webservers{
server 10.0.0.18;
server 10.0.0.28;
}
server {
listen 80;
server_name www.wang.org;
location / {
proxy_pass http://webservers;
}
}
upstream webservers{
server 10.0.0.18 weight=3;
server 10.0.0.28 weight=1;
}
upstream webservers{
server 10.0.0.18 weight 3;
server 10.0.0.28 weight 1;
server 127.0.0.1 backup;
}
upstream webservers{
ip_hash;
server 10.0.0.18 ;
server 10.0.0.28 ;
}
upstream webservers{
least_conn;
server 10.0.0.18 ;
server 10.0.0.28 ;
}
upstream webservers{
hash $remote_addr;
#hash $request_uri;
server 10.0.0.18 ;
server 10.0.0.28 ;
}
upstream webservers{
hash $remote_addr consistent;
server 10.0.0.18 ;
server 10.0.0.28 ;
}
upstream webservers{
hash $cookie_xxx;
server 10.0.0.18 ;
server 10.0.0.28 ;
}
stream {
upstream mysql {
server 11.0.1.48:3306;
server 11.0.1.58:3306;
}
upstream redis {
server 11.0.1.48:6379;
server 11.0.1.58:6379;
}
}
server {
listen 3306;
proxy_pass mysql;
}
server {
listen 6379;
proxy_pass redis;
}
server {
listen 80;
server_name www.wang.org;
root /data/www;
location ~ \.php$|ping|php-status {
root /data/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgu_param HTTPS on;
include fastcgi_params;
}
}