On an apache2 server, I recently cloned an app 'MyApp' from github. But I'm not able to access it through url 133.29.22.57/MyApp/ (ip address is dummy) ? I have tried setting permissions for /var/www/ folder to 777, I also created a new file myapp.conf in etc/apache2/sites-available/ , then I used a2ensite to make it live, then restarted server but still can't access the site. Please help.
Here are the contents of my myapp.conf file :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/MyApp/
<Directory /var/www/MyApp/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Some (possibly) relevant info from apache2.conf
Mutex file:${APACHE_LOCK_DIR} default
# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
#
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
IncludeOptional conf-enabled/*.conf
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
UPDATE
some of the content that you may find relevant which I found under /var/log/apache2/access.log...
169.149.128.75 - - [20/Mar/2017:12:30:49 +0000] "GET /MyApp HTTP/1.1" 404 497 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
169.149.128.75 - - [20/Mar/2017:12:31:01 +0000] "GET /MyApp/index.php HTTP/1.1" 404 507 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
169.149.128.75 - - [20/Mar/2017:12:31:05 +0000] "GET /MyApp/index.php HTTP/1.1" 404 506 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
169.149.128.75 - - [20/Mar/2017:12:31:40 +0000] "GET /MyApp/index.php HTTP/1.1" 404 507 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
::1 - - [20/Mar/2017:12:36:02 +0000] "OPTIONS * HTTP/1.0" 200 125 "-" "Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 (internal dummy connection)"
moreover,
I tried running command /usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE
which says that the following variables are not defined :
${APACHE_LOCK_DIR} ${APACHE_PID_FILE } ${APACHE_RUN_GROUP } ${APACHE_LOG_DIR}
Setting permissions for /var/www/ folder to 777 is a very bad habit.
Give the directory (recursive) to the web server user, usually www-data like "chown -R www-data:www-data /var/www"
Then do a separated log, something like "mywebsite.error.log" and "mywebsite.access.log" so you'll be able to see quickly what's going on.
ErrorLog ${APACHE_LOG_DIR}/mywebsite.error.log
CustomLog ${APACHE_LOG_DIR}/mywebsite.access.log combined
Then tell us more precisely what's going on and I'll update my answer.
Related
I've been scouring trying to find a solution, but when I go to my domain, all my static files are just returning index.html, giving me a
Uncaught SyntaxError: Unexpected token '<' error
My setup is this:
A server that runs nginx for multiple domains, with the one site in question having the following config file
server {
listen 80;
listen [::]:80;
server_name domain.com www.domain.com;
return 302 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/ssl/domain/cert.pem;
ssl_certificate_key /etc/ssl/domain/key.pem;
server_name domain.com www.domain.com;
location / {
proxy_pass http://10.0.0.41:80;
}
location /api {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.0.0.41:3000;
where 10.0.0.41 is another server which is hosting 2 docker containers, one for my react app/nginx and one for my express backend app.
The reverse proxy to the express app works perfect, but when I try to visit domain.com, my js files are returning as index.html and not loading, giving me the error above.
When I visit 10.0.0.41 in my browser, everything loads as it should and works correctly, just not when coming from the domain.
this is the nginx config file for the second server
server {
listen 80;
listen [::]:80;
root /usr/share/nginx/html;
location / {
try_files $uri /index.html;
}
location ~ .(static)/(js|css|media)/(.+)$ {
try_files $uri $uri/ /$1/$2/$3;
}
}
I've tried everything I can find, adding that last line in the 2nd nginx config, removing, adding, changing homepage in package.json.
I am using React router, with <Route exact path="/"
This has been driving me crazy and any help would be greatly appreciated, and if I left out any important information let me know.
Difference in requests:
10.0.0.41:80
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET / HTTP/1.1" 200 644 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET /static/css/main.69847ccd.css HTTP/1.1" 200 2261 "http://10.0.0.41/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET /static/js/main.10f72de5.js HTTP/1.1" 200 514201 "http://10.0.0.41/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET /static/js/423.0a0d8ebb.chunk.js HTTP/1.1" 200 3280 "http://10.0.0.41/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET /favicon.ico HTTP/1.1" 200 3150 "http://10.0.0.41/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
www.domain.com
10.0.0.101 - - [02/Aug/2022:13:44:37 +0000] "GET / HTTP/1.1" 200 644 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "my_ip, cloudflare_ip"
10.0.0.101 - - [02/Aug/2022:13:44:37 +0000] "GET /manifest.json HTTP/1.1" 304 0 "https://www.my_domain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "my_ip, cloudflare_ip"
10.0.0.142 is the machine i'm testing with, 10.0.0.101 is the first nginx server
I have been trying to configure my Apache to list the log files that are stored in /var/log/squid/ so that I can download them from the server to my local PC if required. I have configured the Alias as follows;
Alias /squid/ "/var/log/squid/"
<Directory "/var/log/squid/">
Options None
AllowOverride All
Order allow,deny
Allow from all
</Directory>
But I keep getting the 403 Forbidden error message when I try to browse to the directory.
Apache2 Log Files (CentOS)
172.16.200.132 - - [10/May/2014:14:34:01 +0100] "GET /squid/ HTTP/1.1" 403 288 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
172.16.200.132 - - [10/May/2014:14:34:01 +0100] "GET /squid/ HTTP/1.1" 403 288 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
172.16.200.132 - - [10/May/2014:14:34:01 +0100] "GET /squid/ HTTP/1.1" 403 288 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
172.16.200.132 - - [10/May/2014:14:34:01 +0100] "GET /squid/ HTTP/1.1" 403 288 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
172.16.200.132 - - [10/May/2014:14:34:01 +0100] "GET /squid/ HTTP/1.1" 403 288 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
172.16.200.132 - - [10/May/2014:14:34:01 +0100] "GET /squid/ HTTP/1.1" 403 288 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
172.16.200.132 - - [10/May/2014:14:34:01 +0100] "GET /squid/ HTTP/1.1" 403 288 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
Does anyone have any suggestions, I have tried changing the user Apache runs under to admin which is a user that has full access to the /var/log/squid/ directory but doesn't have access to any system services /etc/init.d/ or the ability to run commands such as (halt, service).
Any suggestion please.
Error Log from Apache
[Mon May 12 17:53:11 2014] [error] [client 172.16.200.132] (13)Permission denied: Can't open directory for index: /var/log/squid/
From the log OP posted, the interesting part is )Permission denied: Can't open directory for index:.
To solve this, change line Options None to Options +Indexes
References: official documentation
I have configured apache2 behind varnish and am trying to add stats by log reading (piwik)
however piwik complains log is "malformed"... and its correct :
89.79.******, 89.79.****** - - [31/Mar/2014:12:50:05 +0200] "GET / HTTP/1.1" 200 16310 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
as you can see it logs the same ip twice as host...
in varnish .vcl i have :
remove req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
and in apache2 vhost :
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined
CustomLog ${APACHE_LOG_DIR}/e***o-access.log varnishcombined
however it still logs the ip twice ...
what can i do to prevent that ?
I ended up using mod_cloudflare :
https://support.cloudflare.com/hc/en-us/articles/200170796-How-do-I-install-mod-cloudflare-on-Apache-
and setting the trusted proxy to 127.0.0.1 + log combined
if anyone has a better solution....
previously i had error in installing apache2 for python, this is the link
I thought i should continue there but right now i'm getting a new error so posting it as a new one this is what the problem is
I have placed a file hello.py having code
#!/usr/bin/python
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'
in a folder /var/www/cgi-bin when I run this on apache2 using
http://localhost/cgi-bin/hello.py
i'm getting this error
The requested URL /cgi-bin/hello.py was not found on this server. Apache/2.2.14(Ubuntu)Server at localhost Port 80
This is the code that i found in the default page in sites-available folder:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
This is what i could find in the error log:
[Fri May 06 13:41:22 2011] [notice] mod_python: using mutex_directory /tmp
[Fri May 06 13:41:22 2011] [notice] Apache/2.2.14 (Ubuntu) mod_python/3.3.1 Python/2.6.5 mod_wsgi/2.8 configured -- resuming normal operations
[Fri May 06 14:23:03 2011] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri May 06 14:23:03 2011] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 284 to 218 : URL /favicon.ico
[Fri May 06 14:23:11 2011] [notice] mod_python (pid=2038, interpreter='127.0.1.1'): Importing module '/var/www/cgi-bin/hello.py'
[Fri May 06 14:23:11 2011] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 289 to 222 : URL /cgi-bin/hello.py
[Fri May 06 14:23:11 2011] [error] /usr/lib/python2.6/dist-packages/mod_python/importer.py:32: DeprecationWarning: the md5 module is deprecated; use hashlib instead
[Fri May 06 14:23:11 2011] [error] import md5
[Fri May 06 14:23:25 2011] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 289 to 222 : URL /cgi-bin/hello.py
This is what i could find in access.log:
172.16.0.73 - - [06/May/2011:02:29:02 +0530] "GET / HTTP/1.1" 200 492 "-" "EZI_WIN_HTTP_AGENT"
172.16.0.73 - - [06/May/2011:02:46:47 +0530] "GET / HTTP/1.1" 200 492 "-" "EZI_WIN_HTTP_AGENT"
127.0.0.1 - - [06/May/2011:14:23:03 +0530] "GET /favicon.ico HTTP/1.1" 404 501 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3"
127.0.0.1 - - [06/May/2011:14:23:10 +0530] "GET /cgi-bin/hello.py HTTP/1.1" 404 504 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3"
127.0.0.1 - - [06/May/2011:14:23:25 +0530] "GET /cgi-bin/hello.py HTTP/1.1" 404 504 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3"
127.0.0.1 - - [06/May/2011:15:10:33 +0530] "GET /cgi-bin/hello.py HTTP/1.1" 404 505 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3"
125.224.195.218 - - [06/May/2011:15:15:10 +0530] "CONNECT 203.188.201.253:25 HTTP/1.1" 405 539 "-" "-"
172.16.0.25 - - [06/May/2011:15:45:53 +0530] "HEAD / HTTP/1.0" 200 277 "-" "-"
127.0.0.1 - - [06/May/2011:21:36:32 +0530] "GET /cgi-bin/hello.py HTTP/1.1" 404 505 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3"
127.0.0.1 - - [06/May/2011:21:36:35 +0530] "GET /favicon.ico HTTP/1.1" 404 500 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3"
Please help me through this.
In your Apache configuration, you need to change the Directory directive to: <Directory /var/www/cgi-bin> if this is where you intend to host your mod_python scripts.
UPDATE:
You're placing your python script in /var/www/cgi-bin but /cgi-bin/ is defined to point to /usr/lib/cgi-bin. You need to standardize on one location for /cgi-bin/.
Here's what I would propose as your corrected Apache configuration. Note that I didn't remove any lines, I only commented out the lines that are not needed or have been replaced.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
#<Directory /var/www>
<Directory /var/www/cgi-bin>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#<Directory "/usr/lib/cgi-bin">
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
#</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
UPDATE 2:
Now that your Apache configuration is correct, and we've verified that your module is importing correctly, you're still getting a 404. This is because you are using the mod_python publisher handler, which expects a different usage than what you have implemented. Basically, you have implemented a simple CGI script that just prints output. mod_python has a specific API for executing your module. You should try this example to get an understanding of how it works.
To implement your test module as a valid mod_python publisher, you could change hello.py to this:
def index(req):
return """<html>
<head>
<title>Hello Word - First CGI Program</title>
</head>
<body>
<h2>Hello Word! This is my first CGI program</h2>
</body>
</html>"""
Note that the reason you were getting a 404 error (even though the module was imported) is explained on this page:
The traversal will stop and
HTTP_NOT_FOUND will be returned to the
client if:
Any of the traversed object's names
begin with an underscore ("_"). Use
underscores to protect objects that
should not be accessible from the web.
A module is encountered. Published
objects cannot be modules for security
reasons.
If an object in the path could not be
found, HTTP_NOT_FOUND is returned to
the client.
Google Page Speed and YSlow says that compression isn't enabled.
Here's my config:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName episodecalendar.com
ServerAlias www.episodecalendar.com
DocumentRoot /var/www/episodecalendar.com/production/current/public/
<Directory /var/www/episodecalendar.com/production/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/www/episodecalendar.com/production/current/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/www/episodecalendar.com/production/current/access.log combined
ServerSignature On
#Gzip/deflate
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog /var/log/apache2/deflate_log deflate
</VirtualHost>
Have I missed something?
mod_deflate IS enabled, and the header says:
Accept-Encoding gzip,deflate
and the actual log looks like this:
"GET /stylesheets/application_packaged.css?1292696861 HTTP/1.1" 6927/31722 (21%)
"GET /stylesheets/print.css?1292696853 HTTP/1.1" 323/625 (51%)
"GET /javascripts/application_packaged.js?1292696861 HTTP/1.1" 25146/74582 (33%)
PS. I run Rails with mod-Passenger
Sorry my bad. I'm behind a proxy server at the office, so by the time it hits my computer, the request is already unpacked.