Htpasswd in Nginx server

Discussion in 'Server Operation' started by SSK, Aug 16, 2020.

  1. SSK

    SSK Member

    I have set the htpasswd for an nginx server to include landing page authentication. However, the authentication is not working. Any suggestion on what change in code is required?

    Current Code:
    location / {
    auth_basic "Restricted Content";
    auth_basic_user_file /path/to/the/folder/.htpasswd;
    #return 301 $scheme://host$request_uri;
    }

    after htpasswd was generated and added to the path to the folder directory.

    It needs to show something like this, https://comedaddymummy.com, which is on an apache server. However, I don't see for the domain on the nginx server. Any suggestions?
     
  2. chaosad

    chaosad New Member

    what kind of error do you get?

    Code:
    location / {
    deny   all;
    auth_basic "Restricted Content";
    auth_basic_user_file /path/to/the/folder/.htpasswd;
    #return 301 $scheme://host$request_uri;
    }
     
    SSK likes this.
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    @SSK: I thought you are using ISPConfig? If this is an ispconfig server, all you have to do for this is using the folder protection feature in the sites module.
     
    SSK and Th0m like this.
  4. SSK

    SSK Member

    =================================================================================
    There is no error to my knowledge. Deny all in this case did not help either.
    location / {
    #return 301 https://$server_name$request_uri;
    #return 301 $scheme://domainname$request_uri;
    deny all;
    auth_basic "Restricted Content";
    auth_basic_user_file /etc/nginx/.htpasswd;
    #return 301 $scheme://domainname$request_uri;
    }

    Output from Nginx -t:
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    /var/log/nginx/error.log:
    2020/08/17 00:54:21 [notice] 10638#10638: signal process started
     
  5. SSK

    SSK Member

    I do use ISPConfig. Due to our current ecosystem management requirements, the nginx server is not placed part of the ISPConfig yet, only the apache containers.

    By the way, there are two issues with the panel that I have noticed. One, when creating a new website, SSL addition does not happen right away and sometimes, require repeating those steps and selecting the buttons again. Is there a specific way to do this?

    For 301 redirect, how can I set the masked redirect from the portal? If possible, please walk down the steps to save both of us time. I can certainly utilize htaccess, which I have done when I relied only on htaccess. However, if this way is easier, why not experiment?

    For example, https://beep.comedaddymummy.com gets redirected to the new url. However, it also shows the new url rather than the above-mentioned one.
     
  6. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    It's better to create a seperate thread for this, but, for your SSL issue, I think you are using LE if things get disabled. Look at this FAQ: https://www.howtoforge.com/community/threads/lets-encrypt-error-faq.74179/

    When you set up a redirect, it does indeed redirect. That's the whole idea. If you don't want to use a redirect, add the url you want to use as alias or subdomain to the website. Keep in mind that 301 is a permanent redirect and you will have to clear your browser cache to see the changes yourself. I recommend using 302 if you want to test a redirect or if it's temporary.
     
    SSK likes this.
  7. SSK

    SSK Member

    SSL: In my case, there is no error. It just does not create the certificate some times. If I turn it off and on again, sometimes it works. Other times, I have to create from the beginning after deleting the created site, and then it goes through.

    301 vs 302: I am looking for 301 permanent redirect. But, I am not certain whether we could mask the redirect using the settings tab. In other words, the redirect is permanent, but I need to see the starting url rather than the ending url.
    https://thumbs.gfycat.com/CelebratedSlimBaldeagle.webp:)

    When it comes to creating a new thread, should we still? Shall we continue over here? Personally, I believe that these are all connected to behind the scene configuration of the server. However, if this community strongly feels to create a new thread for this topic, I will do so..
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    See the link that @Thom posted, it's all explained there to find out why this happens.
     
  9. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    As said before, in that case, you don't want it to redirect, but use a sub-/aliasdomain.

    We are discussing 3 different issues in one thread, which can be confusing for you, me, and other readers. In the future, create separate posts.
     
  10. SSK

    SSK Member

    @Th0m: Sounds good. If I were to participate more in the future, I will keep your suggestion in mind.

    Taking time into account, I usually don't get into these forums as much as possible until I see the need for it. I usually try out different things before sharing my question. Anyways, as per apache rules, using the L-rule should be able to retain the url. However, that is not working.
    https://controlpanel.utixo.co.uk/index.php?rp=/knowledgebase/15/ISPconfig-Redirect-rules.html

    What am I trying to achieve?
    beep.comedaddymummy.com to the below folder keeping the starting url intact

    Current Settings that I have:
    Redirect Type L
    Redirect Path https://val-u-pro.co.in/beep2
    SEO Redirect * => domain.tld
    Rewrite HTTP to HTTPS Selected

    I also noticed that this discussion of masking using ISPConfig has come in howtoforge over the years without clear and concrete answer. It would be helpful to know the right way, if it is possible using the portal.
     
  11. SSK

    SSK Member

    Team:
    Addressed the issue and now, beep.comedaddymummy.com shows up in the address bar. If time permits, check it out (test:123).

    Good day/evening!!
     
  12. SSK

    SSK Member

    Finally, I was able to get the htpasswd working on this nginx server. Thanks to all those who got involved in this discussion.
    https://chillin.aioexplorer.com
     

Share This Page