nginx安装完后发现nginx.conf文件中没有server,只有events{...} 和http{...},这是什么问题?

2025-04-12 13:32:25
推荐回答(1个)
回答1:

这不是问题,nginx在安装完成后默认是这样的。你需要自己在nginx.conf文件中写你自己需要的server配置。我给你个nginx.conf配置文件参考,你可以根据下面的信息来进行修改:

user richmail richmail;  
#worker_processes  4;  
#worker_cpu_affinity 0001 0010 0100 1000;  
worker_rlimit_nofile 65535;  
pid        /home/richmail/nginx/logs/nginx.pid;  
  
events {  
    use epoll;  
    worker_connections 256;   
}  
  
http {  
    include       mime.types;  
    default_type  application/octet-stream;  
    server_tokens off;  
    server_names_hash_bucket_size 128;  
    client_header_buffer_size 32k;  
    large_client_header_buffers 4 32k;  
    sendfile        on;  
    tcp_nopush     on;  
    keepalive_timeout  30;  
    tcp_nodelay on;  
    log_format acc  '$remote_addr - $remote_user [$time_local] "$request" '  
                      '$status $upstream_response_time $body_bytes_sent "$http_referer" "$sent_http_location"'  
                      '"$http_user_agent" "$http_x_forwarded_for"';  
    gzip on;  
    gzip_comp_level 2;  
    gzip_http_version   1.1;  
    gzip_types      text/plain application/x-javascript text/css application/xml text/javascript;  
    gzip_proxied        any;  
    gzip_vary   on;  
  
    proxy_cache_path /home/richmail/nginx/cache levels=1:2 keys_zone=tmp_cache:1024m inactive=20m max_size=1024m;  
    #proxy_set_header X-Forwarded-Proto https;  
    add_header X-Frame-Options SAMEORIGIN;  
    #add_header Cache-Control no-store;   
  
    server {  
        listen       80;  
        server_name _;  
        access_log  /home/richmail/logs/xx.nginx.log acc;  
        error_log  /home/richmail/logs/xx.nginx.err  info;  
        root /home/richmail/nginx/html;  
        proxy_intercept_errors on;  
        error_page   500 /error.html;  
        error_page   404 /404.html;  
user richmail richmail;  
#worker_processes  4;  
#worker_cpu_affinity 0001 0010 0100 1000;  
worker_rlimit_nofile 65535;  
pid        /home/richmail/nginx/logs/nginx.pid;  
  
events {  
    use epoll;  
    worker_connections 256;   
}  
  
http {  
    include       mime.types;  
    default_type  application/octet-stream;  
    server_tokens off;  
    server_names_hash_bucket_size 128;  
    client_header_buffer_size 32k;  
    large_client_header_buffers 4 32k;  
    sendfile        on;  
    tcp_nopush     on;  
    keepalive_timeout  30;  
    tcp_nodelay on;  
    log_format acc  '$remote_addr - $remote_user [$time_local] "$request" '  
                      '$status $upstream_response_time $body_bytes_sent "$http_referer" "$sent_http_location"'  
                      '"$http_user_agent" "$http_x_forwarded_for"';  
    gzip on;  
    gzip_comp_level 2;  
    gzip_http_version   1.1;  
    gzip_types      text/plain application/x-javascript text/css application/xml text/javascript;  
    gzip_proxied        any;  
    gzip_vary   on;  
  
    proxy_cache_path /home/richmail/nginx/cache levels=1:2 keys_zone=tmp_cache:1024m inactive=20m max_size=1024m;  
    #proxy_set_header X-Forwarded-Proto https;  
    add_header X-Frame-Options SAMEORIGIN;  
    #add_header Cache-Control no-store;   
  
    server {  
        listen       80;  
        server_name _;  
        access_log  /home/richmail/logs/xx.nginx.log acc;  
        error_log  /home/richmail/logs/xx.nginx.err  info;  
        root /home/richmail/nginx/html;  
        proxy_intercept_errors on;  
        error_page   500 /error.html;  
        error_page   404 /404.html;  
        error_page   404 /404.html;  
        }  
  
    server {  
        listen       80;  
        server_name webnote.com 127.0.0.1 192.168.34.92;  
        access_log  /home/richmail/logs/mail.nginx.log acc;  
        error_log  /home/richmail/logs/mail.nginx.err  info;  
        proxy_intercept_errors on;  
        error_page   500 502 503 504 /error.html;  
        error_page   404 /404.html;  
        error_page   403 =404 /forbidden.gif;  
        if ($request_method !~* GET|HEAD|POST) {  
                return 400;  
        }  
        include conf.d/note.conf;  
    }  
    server {  
        listen       443;  
        server_name webnote.com 127.0.0.1 192.168.34.92;  
        access_log  /home/richmail/logs/mailssl.nginx.log acc;  
        error_log  /home/richmail/logs/mailssl.nginx.err  info;  
        proxy_intercept_errors on;  
        error_page   500 502 503 504 /error.html;  
        error_page   404 /404.html;  
        error_page   403 =404 /forbidden.gif;  
        if ($request_method !~* GET|HEAD|POST) {  
                return 400;  
        }  
        add_header Cache-Control no-store;  
        add_header Pragma: no-cache;  
        ssl on;  
        ssl_certificate server.pem;  
        ssl_certificate_key privkey.pem;  
        include conf.d/note.conf;  
        }  
}