如何在laginvel 5.x的nginx 1.13.3中配置default.conf

时间:2017-07-28 21:16:47

标签: php laravel nginx laravel-5

在nginx中我们将/ etc / nginx / sites-available / default更改为

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/laravel/public;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name <Your Domain name / Public IP Address>;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.php?$query_string;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}

但是在nginx 1.13.3中我们如何才能进行这些更改?

2 个答案:

答案 0 :(得分:1)

好像你之前使用过ubuntu这就是为什么你找到了sites-availablesites-enabled目录,因为它自己的NGINX在它的设置中没有。所以你可以直接把你的默认配置文件放在

/etc/nginx/conf.d/default  #default is your configuration file

或创建/etc/nginx/sites-available/etc/nginx/sites-enabled,然后修改/etc/nginx/nginx.conf中的 http 块并添加此行

include /etc/nginx/sites-enabled/*;

所有文件都应在sites-available内,然后在sites-enabled

内为它们创建一个符号链接

答案 1 :(得分:0)

默认文件路径:/etc/nginx/sites-available

您也可以在此处创建新文件。

您可以签出laravel的ngnix示例默认文件:https://gist.github.com/sagarjethi/0993c21aa57d220cc90eb8d45cac66c5

server {
    #if single domain then uncomment following line
   # listen 80 default_server;

    server_name example.com www.example.com;  #add your domain name here

    access_log /var/www/laravel-example.com/logs/access.log; # change path as per your application
    error_log /var/www/laravel-example/logs/error.log;

    root /var/www/example.com/public;  #laravel application full path
    index index.php index.html;

    # serve static files directly
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
        log_not_found off;
    }

    # removes trailing slashes (prevents SEO duplicate content issues)
    if (!-d $request_filename)
    {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~* \.php$ {
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock; # may also be: 127.0.0.1:9000;  this path is as your php version
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}