首页 > 解决方案 > 有没有办法在 laravel octane 中指定主机名

问题描述

当我启动 octane 时,它​​总是使用这个主机http ://127.0.0.1:8000,它可用于本地开发,但在生产环境中我使用域名而不是 localhost 有没有办法像http ://domain.com:8000我们启动 octane 时那样更改主机名。

更新: 我正在使用 apache

更新: 我切换到 Nginx,所以它比 apache 工作得更好。但是,如果有人设法在 Apache 中解决了这个问题,欢迎离开您的配置。

标签: laraveloctane

解决方案


你需要 Nginx 或 Apache。它已经在Octane Documentation上。

在下面文件的 Nginx 配置示例中,Nginx 将向运行在端口 8000 上的 Octane 服务器提供站点的静态资产和代理请求:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80; // or 8000
    listen [::]:80; // or 8000
    server_name domain.com;
    server_tokens off;
    root /your/octane_path/public;

    index index.php;

    charset utf-8;

    location /index.php {
        try_files /not_exists @octane;
    }

    location / {
        try_files $uri $uri/ @octane;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/domain.com-error.log error;

    error_page 404 /index.php;

    location @octane {
        set $suffix "";

        if ($uri = /index.php) {
            set $suffix ?$query_string;
        }

        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_pass http://127.0.0.1:8000$suffix;
    }
}

推荐阅读