魔术桌
  • 更新日志
  • 新闻资讯
  • 数据资产
  • 网站导航
  • 订阅推荐
  • 商品推广
  • 日记
  • 摘录
  • 论文
  • 方案
  • 技术
  • 风格
  • 视觉
  • 原材料
  • 加工工艺
  • 元器件
  • 产品设备
  • 设计模式
  • 数据结构
  • 算法设计
  • 软件架构
  • 程序语言
  • 代码类库
  • 操作系统
  • 软件包
  • 健康
  • 环境
  • 社会
  • 道德
  • 法律
  • 经济
  • 政策
  • 更新日志
  • 新闻资讯
  • 数据资产
  • 网站导航
  • 订阅推荐
  • 商品推广
  • 日记
  • 摘录
  • 论文
  • 方案
  • 技术
  • 风格
  • 视觉
  • 原材料
  • 加工工艺
  • 元器件
  • 产品设备
  • 设计模式
  • 数据结构
  • 算法设计
  • 软件架构
  • 程序语言
  • 代码类库
  • 操作系统
  • 软件包
  • 健康
  • 环境
  • 社会
  • 道德
  • 法律
  • 经济
  • 政策
  • Package - Nginx - 配置文件

文章摘要: 摘要内容。

目录结构

/nginx
|-- /client_body_temp
|-- /conf            // 配置文件
|-- /fastcgi_temp
|-- /html            // 前端网页,静态资源
|-- /logs            // 日志文件
|-- /proxy_temp
|-- /sbin            // 可执行程序
|-- /scgi_temp
|-- /uwsgi_temp

配置文件结构

# 上下文
http {
    # 虚拟主机
    server {
        # 资源文件
        location {
            listen 80;
            server_name localhost;
        }
        location {}
        ...
    }
    server {}
    ...

}

虚拟机server通过listen和server_name进行区分,若有多个server配置,则listen和server_name不能重复。

listen:监听可以配置成IP或端口或IP+端口

  • listen 127.0.0.1:8080;
  • listen 127.0.0.1;(端口不写,默认80)
  • listen 8080;
  • listen *:8080;
  • listen localhost:8080;

server:server_name主要用于区分。

默认配置文件


#user  nobody;
worker_processes  1; # 网站数量

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


# 重要配置
events {
    worker_connections  1024; # 每个网站同时能有多少连接
}


# HTTP配置
http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

	# 虚拟主机
    server {
        listen       80; # 端口号
        server_name  localhost; # 主机名/域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

		# URI路径
        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #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;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    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;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

配置 - Web静态网页

  • 配置静态的后台管理系统。
# 虚拟主机
server {
    listen 8080;              # 端口号
    server_name localhost;    # 主机名称
    # 资源文件配置
    location / {
        root /home/blog       # 配置根目录
        index index.html index2.html;   # 首页配置,可配置多个首页
    }
}
更新时间: 2025/10/2 21:54