【问题标题】:how config default.conf in nginx 1.13.3 for laravel 5.x如何在 nginx 1.13.3 中为 laravel 5.x 配置 default.conf
【发布时间】:2018-06-22 14:35:29
【问题描述】:

在 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 中我们如何进行这些更改?

【问题讨论】:

  • 您在寻找 default.conf 吗?如果是这样,您可以在 /etc/nginx/conf.d 或 /etc/nginx/sites-available 中找到它。这取决于您的 /etc/nginx/nginx.conf 文件中包含哪一个。

标签: php laravel nginx laravel-5


【解决方案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 中为它们创建符号链接

【讨论】:

    【解决方案2】:

    默认文件路径:/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;
        }
    }
    

    【讨论】:

    猜你喜欢
    • 2019-01-21
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 2019-11-14
    • 2017-07-25
    • 2015-03-03
    • 2017-03-15
    • 2021-02-05
    相关资源
    最近更新 更多