咱们喜闻乐见的默认配置 nginx.conf

user html; # 专用用户
worker_process 1;
events {
    worker_connections 1024;
}

http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;

    # 虚拟服务器
    server {
        .... # 虚拟服务器配置
    }
}

普通的 http 服务器

server {
    listen 80; # 监听地址
    server_name localhost; # 域名
    
    # 路由
    location / {
        root /srv/http;
        index index.html;
    }
}

错误页重定向

server {
    error_page 404 /404.html;
    
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

PHP 转发到另一个服务器

location ~ \.php$ {
    proxy_pass http://127.0.0.1;
}

PHP 转发到 FastCGI

location ~ \.php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    include fastcgi_params;
}

拒绝访问 .htaccess

location ~ /\.ht {
    deny all;
}

HTTPS

server {
    listen 443 ssl;
    
    ssl_certificate cert.pem;
    ssl_certificate_key cert.key;

    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 5m;

    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
}
Last modification:May 14th, 2020 at 06:44 pm
 Support
如果觉得我的文章对你有用,请随意赞赏