nginx的配置

简介:

lnmpa的环境。

[root@abc conf]# vi /usr/local/nginx/nginx.conf

  gzip_vary on;
  gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
  open_file_cache max=1000 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 2;
  open_file_cache_errors on;

######################## default ############################
  server {
    listen 80;
    server_name _;
    access_log /data/wwwlogs/access_nginx.log combined;
    root /data/wwwroot/www.***.com/public;
    index index.html index.htm index.php;
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    location /nginx_status {

      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
    }
    location / {
      try_files $uri @apache;
    }
    location @apache {
      proxy_pass http://127.0.0.1:88;
      include proxy.conf;
    }
    location ~ [^/]\.php(/|$) {
      proxy_pass http://127.0.0.1:88;
      include proxy.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
      expires 30d;
      access_log off;
    }
    location ~ .*\.(js|css)?$ {
      expires 7d;
      access_log off;
    }
    location ~ /\.ht {
      deny all;
    }
  }
########################## vhost #############################
  include vhost/*.conf;
}
AI 代码解读

[root@abc vhost]# vi /usr/local/nginx/conf/vhost/www.***.com.conf

server {
  listen 443;
  #listen 80;
  ssl on;
  server_name www.***.com;

  ssl_certificate   ../cert/21234224312342.pem;
  ssl_certificate_key  ../cert/21234224312342.key;
  ssl_session_timeout 5m;
  ssl_ciphers ABCDE-ABC-AES128-ABC-SHA256:ABCDE:ABCD:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;

  access_log off;
  index index.html index.htm index.php;
  root /data/wwwroot/www.***.com/public;

  location / {
    try_files $uri @apache;
  }
  location @apache {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
  }
  location ~ .*\.(php|php5|cgi|pl)?$ {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
  }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /\.ht {
    deny all;
  }
}
AI 代码解读

[root@abc vhost]# vi /usr/local/apache/conf/vhost/www.***.com.conf

<VirtualHost *:88>
  ServerAdmin admin@example.com
  DocumentRoot "/data/wwwroot/www.***.com/public"
  ServerName www.***.com

  ErrorLog "/data/wwwlogs/www.***.com_error_apache.log"
  CustomLog "/dev/null" common
<Directory "/data/wwwroot/www.***.com/public">
  SetOutputFilter DEFLATE
  Options FollowSymLinks ExecCGI
  Require all granted
  AllowOverride All
  Order allow,deny
  Allow from all
  DirectoryIndex index.html index.php
</Directory>

AI 代码解读

</VirtualHost>



本文转自phpervip 51CTO博客,原文链接:http://blog.51cto.com/phpervip/2051206,如需转载请自行联系原作者

相关文章
Nginx中配置HTTP2协议的方法
Nginx中配置HTTP2协议的方法
311 7
Nginx进程配置指令详解
Nginx进程配置指令主要包括:`worker_processes`设置工作进程数;`worker_cpu_affinity`绑定CPU核心;`worker_rlimit_nofile`设置最大文件描述符数量;`worker_priority`设置进程优先级;`worker_connections`设置最大连接数;`daemon`控制守护进程模式;`master_process`启用主进程模式;`pid`设置PID文件路径;`user`指定用户和组;`error_log`配置错误日志。这些指令在`nginx.conf`中配置,用于优化和控制Nginx的运行行为。
80 10
Nginx的location配置详解
【10月更文挑战第16天】Nginx的location配置详解
Nginx常用基本配置总结:从入门到实战的全方位指南
Nginx常用基本配置总结:从入门到实战的全方位指南
643 0
nginx配置证书和私钥进行SSL通信验证
nginx配置证书和私钥进行SSL通信验证
142 4
配置Nginx反向代理时如何指定后端服务器的权重?
配置Nginx反向代理时如何指定后端服务器的权重?
301 61
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
330 60
配置Nginx反向代理实现SSL加密访问的步骤是什么?
我们可以成功地配置 Nginx 反向代理实现 SSL 加密访问,为用户提供更安全、可靠的网络服务。同时,在实际应用中,还需要根据具体情况进行进一步的优化和调整,以满足不同的需求。SSL 加密是网络安全的重要保障,合理配置和维护是确保系统安全稳定运行的关键。
423 60
nginx反向代理bucket目录配置
该配置实现通过Nginx代理访问阿里云OSS存储桶中的图片资源。当用户访问代理域名下的图片URL(如 `http://代理域名/123.png`)时,Nginx会将请求转发到指定的OSS存储桶地址,并重写路径为 `/prod/files/2024/12/12/123.png`。
178 5
如何配置Nginx反向代理以实现负载均衡?
如何配置Nginx反向代理以实现负载均衡?
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等