Home  >  Article  >  Backend Development  >  Yii2如何应用配置nginx服务器

Yii2如何应用配置nginx服务器

PHPz
PHPzOriginal
2016-06-06 20:34:492244browse

Yii2如何应用配置nginx服务器

Yii2应用配置nginx服务器的方法:

为了使用 Nginx,你应该已经将 PHP 安装为 FPM SAPI 了。 你可以使用如下 Nginx 配置,将 /home/ahcj/www/basic/web 替换为实际的 basic/web 目录, basic.local 替换为实际的主机名以提供服务。

server {
    charset utf-8;
    client_max_body_size 128M;
    
    ## listen for ipv4
    listen 80;
    ## listen for ipv6
    #listen [::]:80 default_server ipv6only=on;
    server_name  basic.local;
    root        /home/ahcj/www/basic/web;
    index       index.php;
    access_log  /home/ahcj/www/basic/log/access.log;
    error_log   /home/ahcj/www/basic/log/error.log;
    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }
    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;
    location ~ \.php$ {
        include        fastcgi.conf;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #fastcgi_param HTTPS on;
        try_files $uri =404;
    }
    location ~* /\. {
        deny all;
    }
}

使用该配置时,你还应该在 php.ini 文件中设置 cgi.fix_pathinfo=0 , 能避免掉很多不必要的 stat() 系统调用。

还要注意当运行一个 HTTPS 服务器时,需要添加 fastcgi_param HTTPS on; 一行, 这样 Yii 才能正确地判断连接是否安全。

更多相关技术知识,请访问PHP中文网

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn