appstract / laravel-opcache

Laravel Package for OPcache
MIT License
1.34k stars 119 forks source link

The requested URL returned error: 404 Not Found #10

Closed Cannonb4ll closed 7 years ago

Cannonb4ll commented 7 years ago

Whenever I execute php artisan opcache:clear it returns me this error:

php artisan opcache:config

  [Appstract\LushHttp\Exception\LushRequestException]
  The requested URL returned error: 404 Not Found

Am I doing something wrong?

ovanschie commented 7 years ago

Do you have set the correct APP_URL in your .env?

If so, maybe the routes are cached? Try: php artisan routes:clear

Cannonb4ll commented 7 years ago

Yes the APP_URL matches the domain itself 100%.

I have also cleared the route cache and then did php artisan opcache:clear but keep getting the URL error.

teuunn commented 7 years ago

Hi @Cannonb4ll

Can you provide us some more information about your setup or how we can reproduce the issue. Locally I can't reproduce it with latest versions (L5.4.* + laraval-opcache ^0.1.1.)

ovanschie commented 7 years ago

@Cannonb4ll can you respond to above questions please, if the issue still exists? Else we will close this issue.

bradcis commented 7 years ago

I'm running into this as well. I'm wondering if it's because I use CloudFlare? Is there a reason it's referencing the APP_URL rather than '127.0.0.1'? I ask because since I use cloudflare the source IP will never be the same as the server IP.

Cannonb4ll commented 7 years ago

Sorry for responding so late, I have not had the chance to continue on this issue since I just disabled opcache.

ovanschie commented 7 years ago

@bradcis the APP_URL is used because the request must be handled by the same webserver as your site is running on. Only IP would not be enough in most cases, because of the domain mapping to the app. The 'clear' command is requesting the following route for example: <app_url>/opcache-api/clear so this URL should be accessible from your browser, but is should return a 403 error (because the request is not made from the same IP as the server IP) but not a 404 (this implicates that the routes are not working correctly).

Please make sure you are on the latest version, and then report your issues with as much as information as possible.

bradcis commented 7 years ago

@ovanschie, I restarted nginx and now get a 403 when using the artisan opcache commands. Since APP_URL is the production URL, any call made to it gets routed through Cloudflare's servers, and when the call finally gets back to my server, it has a cloudflare IP rather than the server's IP so it doesn't work. It would be great if there was a OPCACHE_APP_URL option in the config which defaulted to APP_URL but that one could override to '127.0.0.1' if they were also using a CDN.

ovanschie commented 7 years ago

@bradcis ok, thanks! will have a look a this later.

ovanschie commented 7 years ago

@bradcis I added 127.0.0.1 to the allowed remotes, so I think this will fix it for you. Can you give it a try?

bradcis commented 7 years ago

@ovanschie, I think we're close. 127.0.0.1 will no longer get a 403, but the artisan commands still reference the APP_URL rather than localhost, so it's still going out onto the Internet and being proxied by the CDN. Could we add a OPCACHE_APP_URL (or similar) config option that defaults to APP_URL but can be overwritten (to http://127.0.0.1/) via the .env file?

ovanschie commented 7 years ago

@bradcis I don't understand the issue with that. If you make a request to http://127.0.0.1/opcache-api/clear how would that be resolved by the webserver? How does it know which app to serve as in most cases it listens for a domain right?

bradcis commented 7 years ago

Good point, I hadn't thought of that. I was assuming there would only be a single app on a server.

If this issue doesn't impact anyone else I don't want to take up anymore of your time, thanks much for your help!

ovanschie commented 7 years ago

@bradcis alright, but did it work even though it is being proxied?