【问题标题】:Deploying Laravel in nginx as reverse proxy with apache在 nginx 中部署 Laravel 作为 apache 的反向代理
【发布时间】:2020-09-24 11:52:11
【问题描述】:

我想在我的服务器中部署我的 laravel 应用程序,使用 nginx 作为 apache 的反向代理,我遇到了以 index.php 开头的 URL 和页面链接的问题。我尝试了没有 index.php 的 url,它可以工作,但是页面中的所有链接都带有 index.php。这是我的配置:

Nginx

server {

    listen  80;
    server_name dev.exemple.com;
    root /var/www/laravel-app/public/;
    index index.php index.htm index.html;

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

    location ~ \.php {
        proxy_pass http://MY-SERVER-IP-ADDRESS:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ /\. {
      deny all;
    }

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

}

阿帕奇

<VirtualHost *:8080>
    ServerName dev.exemple.com
    DocumentRoot /var/www/laravel-app/public/
    <Directory /var/www/laravel-app/>
        AllowOverride All
    </Directory>
</VirtualHost>

【问题讨论】:

    标签: laravel apache nginx deployment nginx-reverse-proxy


    【解决方案1】:

    您好,请从https://laravel.io/forum/10-25-2014-configuration-for-running-laravel-with-nginx-and-apache查看此解决方案

    server {
        listen 80;
        access_log /var/www/site.com/logs/nginx.access.log;
        error_log /var/www/site.com/logs/nginx.error.log;
        root /var/www/site.com/public_html/public;
        index index.php index.html;
        server_name site.com;
    
        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $host;
                proxy_pass http://127.0.0.1:8080;
        }
        location ~* ^.*\.php$ {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $host;
                proxy_pass http://127.0.0.1:8080;
        }
        location ~ /\.(ht|git) {
                deny all;
        }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      • 2010-11-07
      • 2015-10-06
      • 2017-08-09
      • 2018-02-02
      • 2021-07-06
      • 2018-06-14
      相关资源
      最近更新 更多