常用nginx web配置

栏目: 服务器 · Nginx · 发布时间: 4年前

内容简介:常用nginx对于web项目配置整理,做个笔记。

常用nginx对于web项目配置整理,做个笔记。

php web项目配置

server {
  listen 80;
  listen [::]:80;

  # 设置上传最大为5MB
  client_max_body_size 5m;

  root /srv/www/wechat/public;

  index index.html index.php;

  server_name example.com;

  location / {
    try_files $uri $uri/ =404;
  }

  # 支持php
  location ~ \.php$ {
    # Check that the PHP script exists before passing it
    try_files $fastcgi_script_name =404;

    fastcgi_index index.php;
    include fastcgi.conf;

    # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    #  # With php-cgi (or other tcp sockets):
    #  fastcgi_pass 127.0.0.1:9000;
  }

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

php web项目配置 支持 laravel 、symfony、Yii2单入口

...
  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    #try_files $uri $uri/ =404;  # 注释上面这句,使用下面这句
    try_files $uri $uri/ /index.php?$query_string;
  }
...

php web项目配置 支持ThinkPHP

...
  location ~ \.php$ {
    # regex to split $uri to $fastcgi_script_name and $fastcgi_path
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # Check that the PHP script exists before passing it
    try_files $fastcgi_script_name =404;

    # Bypass the fact that try_files resets $fastcgi_path_info
    # see: http://trac.nginx.org/nginx/ticket/321
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;   # ThinkPHP依赖PATH_INFO这个环境变量

    fastcgi_index index.php;
    include fastcgi.conf;

    # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    #  # With php-cgi (or other tcp sockets):
    #  fastcgi_pass 127.0.0.1:9000;
  }
...

php web项目配置 禁止访问上传目录下的 php 文件

...
  # 这个块location要放在 location ~ \.php$ 之前
  location ~ ^/uploads/.*\.php$ {     # 所有/uploads文件目录下的.php文件都被禁止访问
    #deny all;  # 返回403
    return 404; #返回404
  }
...

  nginx


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

JAVA核心技术卷2

JAVA核心技术卷2

Cay S. Horstmann、Gary Cornell / 陈昊鹏、王浩、姚建平 / 机械工业出版社 / 2008-12 / 118.00元

《JAVA核心技术卷2:高级特征》是Java技术权威指南,全面覆盖Java技术的高级主题,包括流与文件、XML、网络、数据库编程、高级Swing、高级 AWT、JavaBean构件、安全、分布式对象、脚本、编译与注解处理等,同时涉及本地化、国际化以及Java SE 6的内容。《JAVA核心技术卷Ⅱ:高级特征》对Java技术的阐述精确到位,叙述方式深入浅出,并包含大量示例,从而帮助读者充分理解Jav......一起来看看 《JAVA核心技术卷2》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具