laravel octane: 配置nginx访问octane(laravel 11)

一,配置 nginx

1,一个nginx的server段

在server段之外添加:

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

在server段中添加如下内容:

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

        location / {
            try_files $uri $uri/ @octane;
        }
    
    
    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;
    }

说明:8000是octane的守护端口

2,一个例子:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        # root /var/www/html;
        root /data/api/public;

        # Add index.php to the list if you are using PHP
        # index index.php index.html index.htm index.nginx-debian.html;
        index index.php;

        server_name _;

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

        location / {
            try_files $uri $uri/ @octane;
        }
    
    
    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;
    }
}

 

二,完成之后重启nginx服务

# systemctl restart nginx.service

然后可以通过nginx的域名和端口访问

 

posted @ 2024-11-08 14:55  刘宏缔的架构森林  阅读(29)  评论(0编辑  收藏  举报