Nginx常用nginx.conf配置文件代码

[复制链接]
admin 发表于 2025-9-13 12:06:39 | 显示全部楼层 |阅读模式
Nginx常用nginx.conf配置文件代码


  1. #user  nobody;
  2. worker_processes  1;

  3. #error_log  logs/error.log;
  4. #error_log  logs/error.log  notice;
  5. #error_log  logs/error.log  info;

  6. #pid        logs/nginx.pid;


  7. events {
  8.     worker_connections  1024;
  9. }


  10. http {
  11.     include       mime.types;
  12.     default_type  application/octet-stream;

  13.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  14.     #                  '$status $body_bytes_sent "$http_referer" '
  15.     #                  '"$http_user_agent" "$http_x_forwarded_for"';

  16.     #access_log  logs/access.log  main;

  17.     sendfile        on;
  18.     #tcp_nopush     on;

  19.     #keepalive_timeout  0;
  20.     keepalive_timeout  65;

  21.     #gzip  on;
  22.         
  23.         map $http_upgrade $connection_upgrade{
  24.                 default upgrade;
  25.                 '' close;
  26.         }

  27.         upstream webservers{
  28.           server 127.0.0.1:8080 weight=90 ;
  29.           #server 127.0.0.1:8088 weight=10 ;
  30.         }

  31.     server {
  32.         listen       90;
  33.         server_name  localhost;

  34.         #charset koi8-r;

  35.         #access_log  logs/host.access.log  main;

  36.         location / {
  37.             root   html/sky;
  38.             index  index.html index.htm;
  39.         }

  40.         #error_page  404              /404.html;

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

  47.         # 反向代理,处理管理端发送的请求
  48.         location /api/ {
  49.                         proxy_pass   http://localhost:8080/admin/;
  50.             #proxy_pass   http://webservers/admin/;
  51.         }
  52.                
  53.                 # 反向代理,处理用户端发送的请求
  54.         location /user/ {
  55.             proxy_pass   http://webservers/user/;
  56.         }
  57.                
  58.                 # WebSocket
  59.                 location /ws/ {
  60.             proxy_pass   http://webservers/ws/;
  61.                         proxy_http_version 1.1;
  62.                         proxy_read_timeout 3600s;
  63.                         proxy_set_header Upgrade $http_upgrade;
  64.                         proxy_set_header Connection "$connection_upgrade";
  65.         }

  66.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  67.         #
  68.         #location ~ \.php$ {
  69.         #    root           html;
  70.         #    fastcgi_pass   127.0.0.1:9000;
  71.         #    fastcgi_index  index.php;
  72.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  73.         #    include        fastcgi_params;
  74.         #}

  75.         # deny access to .htaccess files, if Apache's document root
  76.         # concurs with nginx's one
  77.         #
  78.         #location ~ /\.ht {
  79.         #    deny  all;
  80.         #}
  81.     }


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

  88.     #    location / {
  89.     #        root   html;
  90.     #        index  index.html index.htm;
  91.     #    }
  92.     #}


  93.     # HTTPS server
  94.     #
  95.     #server {
  96.     #    listen       443 ssl;
  97.     #    server_name  localhost;

  98.     #    ssl_certificate      cert.pem;
  99.     #    ssl_certificate_key  cert.key;

  100.     #    ssl_session_cache    shared:SSL:1m;
  101.     #    ssl_session_timeout  5m;

  102.     #    ssl_ciphers  HIGH:!aNULL:!MD5;
  103.     #    ssl_prefer_server_ciphers  on;

  104.     #    location / {
  105.     #        root   html;
  106.     #        index  index.html index.htm;
  107.     #    }
  108.     #}

  109. }
复制代码

网站建设,公众号小程序开发,多商户单商户小程序制作,高端系统定制开发,App软件开发联系我们【手机/微信:17817817816
微信扫码

网站建设,公众号小程序开发,商城小程序,系统定制开发,App软件开发等

粤ICP备2024252464号

在本版发帖
微信扫码
QQ客服返回顶部
快速回复 返回顶部 返回列表