تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Locking Down Staging0:00

At the moment, anyone in the world can visit this URL, but we probably want to lock it down so it's administrators only or staff only. Let's tackle that in this episode. I will once again ssh into our server, and then I will cd into our staging website, and I'm going to use a htpasswd tool here. However, if we run it, we may come across this. It's not installed. All right. The apache2-utils. There we go.

Creating htpasswd File0:28

The Apache utils. There we go. So this allows us to create a password for basic authentication. So if we run this, we're going to create a new password file, and we're going to put it in the home directory, forge, let's see, in our staging site. Now we'll call the file .htpasswd, and then we need a variable username. It can be myself, and we'll do that, admin, whatever you want. Let's do this. Okay. I will enter a password.

Okay. I will enter a password. I'm just going to type in the string password there. So you can try it out live if you want. And there we go. So now if I list the files, you'll see right, where is it? There it is. We now have that file. And if we cat it, you'll see our username and a password. Okay.

Editing Nginx Config1:12

And if we cat it, you'll see our username and a password. Okay. We're not quite done yet. We have to now switch over to our server. I'm in my staging site, and we'll scroll down. And right here, I can edit my nginx configuration, or of course, you can do it directly in the server with them. So let's see. I know this can get a little confusing. Right here, location.

Enabling Basic Auth1:32

I know this can get a little confusing. Right here, location. So this is going to apply to basically everything. So try to load the file, redirect to index.php along with the query string. That's how we handle that with Laravel applications. But also, we're going to turn on basic auth. We do it like so. Auth::basic, and we'll say the title or the message to the user will be staff only. And then we need the user file. And that will be, I can't remember, what did we call it?

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟