Error 401 only sometimes

Hey,

So I'm running a few websites on a single server with a apache2, php, and mysql configuration. Depending on the connection being used the server either responds with the webpage requested or an error 401 authentication needed. Cell phones are a big one for this: on LTE or 3G connection the website will never load.

Sorry I'm fairly new in this stuff and I don't know which files to even begin to look at for fixing this; especially for the network side of things.

Thanks,

Waddle.

10 Replies

Hey there,

Thank you for reaching out. There can be possibly a few reasons for this, but the best way to help will be to provide us with the domain you are using and the IP address of the server. Also, I would recommend taking a look at your Apache logs to see if there are any errors reported.

Thanks in advance!

Regards,

Stephen Crane…

Linode Customer Support

scrane is right; without more details or log info there's not much we can do to help. I would point out that many cell phones in the U.S. connect via IPv6 if it's available rather than IPv4; you may want to look and see if your site is working properly over both.

Hey,

Currently the two domains being used are muzombies.org and trumanzombies.org. The apache logs say two things:

One, a file /htdocs does not exist

Two, there are a few invalid method in request.

Both of these are for the server in general. When I delve into just the individual websites' error logs the biggest problem seems to be different users are not found. I am fairly certain that this is an entire server problem as both websites do the same thing.

Also, the error 401 authorization does allow the server user name/password combination through to myphpadmin which is set up as the last virtual host in the websites' config files. Could it be that the system routes the clients to the wrong virtual host?

To answer Vance, both IPv6 and IPv4 are configured from what I can tell. The server is listening to ports under each.

Thank you!

Looks to me like this is an IPv6 issue. I think Vance was on the right rack here. Trying to curl the site, I get the following:

curl -6v muzombies.org

  • Rebuilt URL to: muzombies.org/

  • Trying 2600:3c03::f03c:91ff:fe92:9388…

  • Connected to muzombies.org (2600:3c03::f03c:91ff:fe92:9388) port 80 (#0)

GET / HTTP/1.1

Host: muzombies.org

User-Agent: curl/7.47.0

Accept: /

>

< HTTP/1.1 401 Authorization Required

< Server: Apache/2.2.14 (Ubuntu)

< WWW-Authenticate: Basic realm="Restricted"

< Vary: Accept-Encoding

< Content-Type: text/html; charset=iso-8859-1

< Content-Length: 480

< Accept-Ranges: bytes

< Date: Tue, 07 Nov 2017 21:27:29 GMT

< X-Varnish: 1670810917

< Age: 0

< Via: 1.1 varnish

< Connection: keep-alive

<

401 Authorization Required

Authorization Required

This server could not verify that you

are authorized to access the document

requested. Either you supplied the wrong

credentials (e.g., bad password), or your

browser doesn't understand how to supply

the credentials required.


Apache/2.2.14 (Ubuntu) Server at muzombies.org Port 80
  • Connection #0 to host muzombies.org left intact

You're going to want to make sure your virtual hosts configurations include IPv6, or you should disable IPv6 and remove the AAAA records from your DNS. I think either of those two options should clear up what you are seeing.

EDIT: I should add, I don't experience this issue curling the domain over IPv4, but when I curl the IPv4 address directly, I get the same response:

curl -v 50.116.59.6

  • Rebuilt URL to: 50.116.59.6/

  • Trying 50.116.59.6…

  • Connected to 50.116.59.6 (50.116.59.6) port 80 (#0)

GET / HTTP/1.1

Host: 50.116.59.6

User-Agent: curl/7.47.0

Accept: /

>

< HTTP/1.1 401 Authorization Required

< Server: nginx/1.4.1

< Date: Tue, 07 Nov 2017 21:34:29 GMT

< Content-Type: text/html; charset=iso-8859-1

< Content-Length: 478

< Connection: keep-alive

< WWW-Authenticate: Basic realm="Restricted"

< Vary: Accept-Encoding

<

401 Authorization Required

Authorization Required

This server could not verify that you

are authorized to access the document

requested. Either you supplied the wrong

credentials (e.g., bad password), or your

browser doesn't understand how to supply

the credentials required.


Apache/2.2.14 (Ubuntu) Server at 50.116.59.6 Port 80
  • Connection #0 to host 50.116.59.6 left intact

This I think confirms that what's happening is the virtual hosts don't include the IPv6 addresses, so instead of directing to the correct root folder we get redirected to the default page which is giving the 401.

So what do I have to change in the virtual host file and ports.conf file to add IPv6 availability?

The virtual host file:

ServerAdmin support@localhost

ServerName muzombies.org

DocumentRoot …

ErrorLog …

CustomLog …

Options FollowSymLinks

AllowOverride All

Order allow,deny

allow from all

And the ports.conf file:

NameVirtualHost IPv4 address:8080

Listen 8080

Do I need to add a listen to other ports then add that the website should also listen to said ports?

I believe you'll need to set up a separate host file with the following:

DocumentRoot /var/www/second/

ServerName second.domain

ServerAlias www.second.domain

ErrorLog …

CustomLog …

I think this guide should help:

https://serverfault.com/questions/33240 … -with-ipv6">https://serverfault.com/questions/332409/how-to-set-apache-virtualhost-to-work-with-ipv6

Actually, sorry, just realized I shared Apache configurations. One second while I pull up what you'll need for nginx.

EDIT: Actually, double checking. Are you currently using Nginx or Apache? Because when I check, I get the following:

curl -4Il http://muzombies.org/

HTTP/1.1 200 OK

Server: nginx/1.4.1

Date: Tue, 07 Nov 2017 22:23:20 GMT

Content-Type: text/html

Connection: keep-alive

X-Powered-By: PHP/5.3.2-1ubuntu4.9

Set-Cookie: PHPSESSID=fs9d265sni9lrod3qrubj89c13; path=/

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Vary: Accept-Encoding

But then on IPv6 I get the following:

curl -6Il http://muzombies.org/

HTTP/1.1 401 Authorization Required

Server: Apache/2.2.14 (Ubuntu)

WWW-Authenticate: Basic realm="Restricted"

Vary: Accept-Encoding

Content-Type: text/html; charset=iso-8859-1

Date: Tue, 07 Nov 2017 22:24:27 GMT

X-Varnish: 1670810920

Age: 0

Via: 1.1 varnish

Connection: keep-alive

Also, I would recommend taking a look at this guide:

https://www.linode.com/docs/websites/ho … tual-hosts">https://www.linode.com/docs/websites/hosting-a-website#configure-name-based-virtual-hosts

Within the process of doing that. I have managed all but restarting apache2. It comes out with a address already in use: make_sock: … With a little research I figured out that the ports needed to be cleared. Doing that has lead me to not having access to the websites at all anymore and somehow even when the address are not in use, they are.

The two addresses are [::]:8080 and 0.0.0.0:8000

I don't get it. netstat -tulpn says they aren't in use but there is no connecting when I restart apache2. I'm just confused now.

Update: I figured out what was the issue and got the system restarted with the new lines. No luck to get it set.

The ports.config file for apache says this:

Nginx reverse-proxy

NameVirtualHost IP.address.v4:8080

Listen 8080

Add IPv6?

NameVirtualHost [IP.address.v6]:8180

Listen 8180

Varnish reverse proxy

NameVirtualHost [IP.address.v4]:8000

Listen 8000

So overall I am not sure which one I am using. I did not set this server up initially. I am apart of an org and the current webmaster so I was passed it down from the last person. All of the sites are enabled through apache and the nginx folder has only the default in it. So I would guess from that its Apache.

When I run 'netstat -tulpn | grep tcp' I get results that include

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17880/varnishd

tcp6 0 0 :::8180 :::* LISTEN 19915/apache2

tcp6 0 0 :::8000 :::* LISTEN 19915/apache2

tcp6 0 0 :::8080 :::* LISTEN 19915/apache2

tcp6 0 0 :::80 :::* LISTEN 17880/varnishd

I'm sorry I'm not understanding the details straight off the bat. I'm an ECE major so I'm a little out of my area. However, I've learned a lot. Thank you for your help so far. Hopefully, this gets cleared up soon!

FINALLY,

so scrane, since you asked about nginx I went in and looked at the file system. It is installed and the default was enabled. I looked into the configuration file and nginx forwards the requests on to apache under the local ipaddress. I was trying to change the values in the wrong place the entire time due to this. However, the websites now seem functional so I'm going with it.

Thank you again for all your help.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct