301 moved permanently linux

Why does my apache2 setup always result in 301 Moved Permanently

I recently set up an apache2 (2.4) server on a VPS, trying to get it to run a rails app with Phusion Passenger. It’s nearly a fresh install of Ubuntu 14.04 and apache2. I’m trying to get a VirtualHost entry configured via sites-enabled. As soon as I ran a2ensites, any access to the http://my.site would be automatically be redirected to https://my.site. I don’t have any .htaccess file anywhere. The following illustrates what I am having trouble with. Here’s /etc/apache2/ and there’s no virtual host site enabled as of now

[appuser@prod apache2]$ ls -l total 84 -rw-r--r-- 1 root root 7115 Jan 7 08:23 apache2.conf drwxr-xr-x 2 root root 4096 May 8 21:46 conf-available drwxr-xr-x 2 root root 4096 May 8 21:46 conf-enabled -rw-r--r-- 1 root root 1782 Jan 3 09:48 envvars -rw-r--r-- 1 root root 31063 Jan 3 09:48 magic drwxr-xr-x 2 root root 12288 May 8 22:11 mods-available drwxr-xr-x 2 root root 4096 May 13 00:28 mods-enabled -rw-r--r-- 1 root root 320 Jan 7 08:23 ports.conf drwxr-xr-x 2 root root 4096 May 12 23:37 sites-available drwxr-xr-x 2 root root 4096 May 13 00:40 sites-enabled drwxr-xr-x 2 root root 4096 May 8 22:24 ssl [appuser@prod apache2]$ ls -l sites-enabled/ total 0 
[appuser@prod apache2]$ cat sites-available/bulletin.vhost.conf #NameVirtualHost *:80 #ServerName bulletin.xorg ServerName bulletin.xorg:80 DocumentRoot /home/appuser/www/bulletin/public AllowOverride all Options -MultiViews Require all granted PassengerRuby /home/appuser/.rvm/gems/ruby-1.9.3-p545/wrappers/ruby  
[appuser@prod apache2]$ wget http://xorg --2014-05-13 00:53:46-- http://xorg/ Resolving xorg (xorg). 127.0.0.1 Connecting to xorg (xorg)|127.0.0.1|:80. connected. HTTP request sent, awaiting response. 200 OK Length: 739 [text/html] 
[appuser@prod apache2]$ sudo a2ensite bulletin.vhost [sudo] password for appuser: Enabling site bulletin.vhost. To activate the new configuration, you need to run: service apache2 reload [appuser@prod apache2]$ )`reload': sudo service apache2 reload * Reloading web server apache2 [appuser@prod apache2]$ sudo service apache2 restart * Restarting web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message 

Now I’m having trouble getting to either http: //xorg or http://bulletin.xorg. I’m always getting «301 Moved Permanently» status.

[appuser@prod apache2]$ wget http://xorg --2014-05-13 00:58:45-- http://xorg/ Resolving xorg (xorg). 127.0.0.1 Connecting to xorg (xorg)|127.0.0.1|:80. connected. HTTP request sent, awaiting response. 301 Moved Permanently Location: https://xorg/ [following] --2014-05-13 00:58:45-- https://xorg/ Connecting to xorg (xorg)|127.0.0.1|:443. connected. OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol Unable to establish SSL connection. [appuser@prod apache2]$ wget http://bulletin.xorg --2014-05-13 01:01:18-- http://bulletin.xorg/ Resolving bulletin.xorg (bulletin.xorg). 127.0.0.1 Connecting to bulletin.xorg (bulletin.xorg)|127.0.0.1|:80. connected. HTTP request sent, awaiting response. 301 Moved Permanently Location: https://bulletin.xorg/ [following] --2014-05-13 01:01:19-- https://bulletin.xorg/ Connecting to bulletin.xorg (bulletin.xorg)|127.0.0.1|:443. connected. OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol Unable to establish SSL connection. 

If it’s of any interest, I have the following mods enabled and created a self-signed ssl certificate earlier (I don’t see how it can be relevant though):

[appuser@prod apache2]$ ls -l ssl/ total 8 -rw-r--r-- 1 root root 1350 May 8 22:24 redmine.crt -rw-r--r-- 1 root root 1704 May 8 22:24 redmine.key [appuser@prod apache2]$ ls -l mods-enabled/ . . lrwxrwxrwx 1 root root 30 May 13 00:28 rewrite.load -> ../mods-available/rewrite.load . . lrwxrwxrwx 1 root root 26 May 8 21:47 ssl.conf -> ../mods-available/ssl.conf lrwxrwxrwx 1 root root 26 May 8 21:47 ssl.load -> ../mods-available/ssl.load . . 

Источник

Читайте также:  Run linux using virtualbox

Why nginx works with error 301 HTTP1.1/Moved permanently?

I’m trying to configure Location directive on my nginx web-server (Ubuntu). I can have access to: http://127.0.0.1/app1/ BUT when I’m trying to get access whitout slash in the end like: http://127.0.0.1/app1 I get an error 301 HTTP1.1/Moved permanently I have following nginx config:

user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events < worker_connections 768; >http < sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; >
root@ubuntu-test:/etc/nginx/sites-available# curl 127.0.0.1/app1/ -Iv * Trying 127.0.0.1. * TCP_NODELAY set * Connected to 127.0.0.1 (127.0.0.1) port 80 (#0) > HEAD /app1/ HTTP/1.1 > Host: 127.0.0.1 > User-Agent: curl/7.58.0 > Accept: */* > < HTTP/1.1 200 OK HTTP/1.1 200 OK < Server: nginx/1.14.0 (Ubuntu) Server: nginx/1.14.0 (Ubuntu) < Date: Thu, 20 Feb 2020 09:14:12 GMT Date: Thu, 20 Feb 2020 09:14:12 GMT < Content-Type: text/html Content-Type: text/html < Content-Length: 5 Content-Length: 5 < Last-Modified: Tue, 18 Feb 2020 10:49:53 GMT Last-Modified: Tue, 18 Feb 2020 10:49:53 GMT < Connection: keep-alive Connection: keep-alive < ETag: "5e4bc151-5" ETag: "5e4bc151-5" < Accept-Ranges: bytes Accept-Ranges: bytes < * Connection #0 to host 127.0.0.1 left intact 
 root@ubuntu-test:/etc/nginx/sites-available# curl 127.0.0.1/app1 -Iv * Trying 127.0.0.1. * TCP_NODELAY set * Connected to 127.0.0.1 (127.0.0.1) port 80 (#0) > HEAD /app1 HTTP/1.1 > Host: 127.0.0.1 > User-Agent: curl/7.58.0 > Accept: */* > < HTTP/1.1 301 Moved Permanently HTTP/1.1 301 Moved Permanently < Server: nginx/1.14.0 (Ubuntu) Server: nginx/1.14.0 (Ubuntu) < Date: Thu, 20 Feb 2020 09:19:31 GMT Date: Thu, 20 Feb 2020 09:19:31 GMT < Content-Type: text/html Content-Type: text/html < Content-Length: 194 Content-Length: 194 < Location: http://127.0.0.1/app1/ Location: http://127.0.0.1/app1/ < Connection: keep-alive Connection: keep-alive 

1 Answer 1

Nginx selects the location / block to process the URI /app1 as no other locations are a better match. See how Nginx processes a request.

Читайте также:  Hp m428dw driver linux

The $uri/ term of the try_files statement informs Nginx to append a / to any URI that matches a directory. The directory /var/www/html/app1 matches this requirement, so a 301 redirection is generated to append a / to the URI. See this document for details.

In addition, the default behaviour for a URI which ends with a / and points to a directory is to search that directory for a file that matches the index directive. See this document for details.

It is possible to deviate from this default behaviour, but you will need to make a number of changes to your configuration. The location /app1/ needs to lose the trailing / if you want it to match /app1 . Your try_files directives need to lose the $uri/ term, if you want to avoid the 301 redirect. You will also lose default index processing, so the index directive will be useless.

Источник

Оцените статью
Adblock
detector