Search code examples
laravelapachenginxcentos

403error (Laravel + Nginx + Apache) CentOS 8


I'm trying to configure the site to work with Nginx and Apache. When I try to reach the site, I get a 403 error.

In the file /etc/httpd/conf/httpd.conf I set the default port 8089 (since 8080 is already busy):

Listen 127.0.0.1:8089

Next, I create a config for Apache (/etc/httpd/conf.d/site.conf):

<VirtualHost 127.0.0.1:8089>
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot "/usr/share/site/public"

    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined

    <Directory "/usr/share/site/public">
        Require all granted
        AllowOverride all
    </Directory>
</VirtualHost>

Finally, I create a config for Nginx (/etc/nginx/conf.d/site.conf):

server {
    listen      80;
    server_name site.com www.site.com;
    root        /usr/share/site/public;
    
    charset utf-8;
    
    gzip on;
    gzip_types 
        text/css 
        application/javascript 
        text/javascript 
        application/x-javascript
        image/svg+xml 
        text/plain 
        text/xsd 
        text/xsl 
        text/xml 
        image/x-icon;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php {
        proxy_pass http://localhost:8089;
        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 ~ /\.ht {
        deny all;
    }
}

What could be the problem?


Solution

  • Good Day!

    try this original config by laravel ref link https://laravel.com/docs/7.x/deployment

    server {
        listen 80;
        server_name site.com www.site.com;
        root /usr/share/site/public;
    
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";
    
        index index.php;
    
        charset utf-8;
    
        gzip on;
        gzip_types 
            text/css 
            application/javascript 
            text/javascript 
            application/x-javascript
            image/svg+xml 
            text/plain 
            text/xsd 
            text/xsl 
            text/xml 
            image/x-icon;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
    
        error_page 404 /index.php;
    
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;  
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.(?!well-known).* {
            deny all;
        }
    }
    

    NOTE: fastcgi_pass u need to change php{version}-fpm.sock; based on your version