Day 43rd: Questions related to Apache

Source: Internet
Author: User
Tags apache php log log php error php error log

Small Q:       the will and labor of life will create miraculous miracles. --Necrasov

Apache Set Custom Header-----------------------------------------

1. Before you set up your custom header, you need to check if your httpd is loaded mod_headers

/usr/local/apache2/bin/apachectl-l

Otherwise, it needs to be recompiled.

2. Add in the httpd.conf

<ifmodule mod_headers.c>

Header add MyHeader "Hello"

</IFModule>

Save restart; The contents of the double quotation marks are custom content

3. Testing

Curl-i http://localhost See if MyHeader "Hello" is displayed

Apache settings prohibit access to. txt files---------------------------------------

Options-indexes FollowSymLinks

AllowOverride All

Order Allow,deny

Deny from all

Access always points to the first virtual host--------------------------------------

When configuring multiple Apache virtual hosts, access always points to the first virtual host,

Add Namevirtualhost * To solve the problem.

Namevirtualhost *

<virtualhost *>

DocumentRoot "f:/web/"

ServerName localhost

</VirtualHost>

The proxy IP and the real client IP are recorded in the log---------------------------------

By default, the log log format is:

Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined

Where%h is the IP of the record visitor, if there is a layer of proxy in the front of the web, then this%h is actually the IP of the proxy machine, this is not what we want. In this case,

The%{x-forwarded-for}i field records the client's true IP. So log logs should read:

Logformat "%h%{x-forwarded-for}i%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined

Apache Expansion Module Installation-------------------------------------------

This uses the Apache extension tool APXS; Please verify that the MOD_SO module has been loaded by:

/usr/local/apache2/bin/httpd-l

Below, how to compile and install the Extension Module mod_status.so this module

/usr/local/apache2/bin/apxs-i-a-c MOD_STATUS.C

Please note that the path of the mod_status.c here must be written right, otherwise it will error, in general, the C file in your source package, such as:

/usr/local/src/httpd-2.0.59/modules/generators/mod_status.c

The result of the compilation is similar to this:

/usr/local/services/apache-2.0.59/build/libtool --silent --mode=compile gcc -prefer-pic   -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g  -o2 -pthread -i/usr/local/services/apache-2.0.59/include  -i/usr/local/services/ Apache-2.0.59/include   -i/usr/local/services/apache-2.0.59/include   -c -o  /root/httpd-2.0.64/modules/generators/mod_status.lo /root/httpd-2.0.64/modules/generators/mod_ status.c && touch /root/httpd-2.0.64/modules/generators/mod_status.slo/usr/local/ services/apache-2.0.59/build/libtool --silent --mode=link gcc -o /root/httpd-2.0.64/ Modules/generators/mod_status.la  -rpath /usr/local/services/apache-2.0.59/modules -module  -avoid-version    /root/httpd-2.0.64/modules/generators/mod_status.lo/usr/local/ services/apache-2.0.59/build/instdso.sh sh_libtool= '/usr/local/services/apache-2.0.59/build/libtool '  /root/httpd-2.0.64/modules/generators/ Mod_status.la /usr/local/services/apache-2.0.59/modules/usr/local/services/apache-2.0.59/build/libtool  --mode=install cp /root/httpd-2.0.64/modules/generators/mod_status.la /usr/local/services /apache-2.0.59/modules/path= "$PATH:/sbin"  ldconfig -n /usr/local/services/apache-2.0.59/ Modules----------------------------------------------------------libraries have been installed  in:   /usr/local/services/apache-2.0.59/modules

When you're done, see the Tip Libraries has been installed in: The module will be installed here.

Uploading large files over HTTP time-out problem-------------------------------------

The schema is LAMP, the operation of uploading files, and not connected to MySQL, but the use of PHP resources, so modify the settings, not only to set Apache also set php.ini

1. Apache httpd.conf Settings

Timeout 600 This can be set to 3600, unit is s

2. Parameters related to PHP.ini

File_uploads = on; #默认为开upload_max_filesize = 1024M; #上传最大值post_max_size = 1024M; #通过表单POST给PHP的所能接收的最大值如果还不行, let's modify the following parameters. Max_execution_time = 0; #每个php脚本的最大执行时间, the unit is seconds.       0 means no limit max_input_time = 600000; #传送请求数据的最大时间, seconds.   Change the big ... memory_limit = 500M; #一个脚本占用内存的上限. This does not suggest too much. In the event of an attack, your machine will collapse. Recommended up to 256M.

Mod_proxy Expansion Module Installation-----------------------------------------

First, when compiling, add the parameter--enable-proxy--enable-proxy-http;

If not compiled into this module to go? How to do it, can be compiled by extension.

Download the same version of the Apache source code, note that must be the same version, or the compilation will not succeed.

After downloading, unzip

CD Httpd-2.0.59/modules/proxy

/usr/local/apache2/bin/apxs-c-i-a mod_proxy.c proxy_connect.c proxy_http.c proxy_util.c

From the output see Apache modules directory has produced mod_proxy.so, and has been activated in httpd.conf

cd/usr/local/apache2/conf/

Ls.. /modules/saw that there was mod_prxoy.so.

Editing a configuration file

VI httpd.conf

Modify the following

Loading modules

LoadModule Proxy_module modules/mod_proxy.so (This is generated when compilation is activated)

LoadModule Proxy_http_module modules/mod_proxy.so (this sentence is to be added manually)

Change the configuration file

<virtualhost *:80> ServerName www.test.com customlog "/dev/null" combined proxyrequests Off <proxy *> Order Deny,allow allow from all </Proxy> Proxypass/http://www.test.com/proxypa Ssreverse/192.168.13.111/</virtualhost>

It is also important to note that you need to add a record to the/etc/hosts

192.168.13.111 www.test.com



==================================== Exercises ==========================================

1. Why download the source package to the official website to download?

Simply said is for security, if it is unofficial download source package, there may be ulterior motives of people moved hands and feet, after all, is the source, anyone can modify the code.


2. Can 64-bit machines install 32-bit RPM packages? Can a 64-bit machine install a 32-bit MySQL binary-free compiler package?

The 64-bit machine is capable of installing a 32-bit RPM package, and the same 64-bit machine can also install a 32-bit MySQL binary-free compiler package (centos5.x does support it, but centos6.x does not).


3. When compiling and installing Apache, what is the problem if you do not add--with-included-apr?

will be error, cannot use a external APR with the bundled apr-util, because APR is a bottom-level interface library, compiling Apache must have this support.


4. When compiling PHP, you must add--with-apxs2=/usr/local/apache2/bin/apxs what does that mean?

APXS is a tool that Apache compiles dynamic modules and automatically configures to load into httpd.conf files, and since PHP is also a dynamic loading module for Apache, we compile PHP to generate this module, so we have to specify the address of the APXS.


5. After configuring the Apache configuration file, how to verify the configuration file is correct?

/usr/local/apache2/bin/apachectl-t


6. How do I see if 80 ports are started?

NETSTAT-LNP |grep ': 80 '


7. How do I reload the configuration file after I change the Apache profile httpd.conf?

/usr/local/apache2/bin/apachectl Graceful


8. How do I see which modules are loaded by Apache?

/usr/local/apache2/bin/apachectl-m


9. How do I see which modules are loaded by PHP?

/usr/local/php/bin/php-m


10. Simply describe the difference between static loading and dynamic shared modules.

Whether compiling httpd or PHP, there is a concept of static modules and dynamic modules. First of all, dynamic and static module macro analysis, the static will be directly compiled into the httpd executable file, and the dynamic module is a separate file, and secondly, the static module is loaded with httpd this file, as long as the service will load all static modules, Dynamic modules are based on when the demand is loaded.


11. When we configure the lamp environment, access to the PHP program can not be resolved, how do you troubleshoot this problem?

(1) apachectl-m See if the libphp5.so is loaded

(2) If not loaded, see if/usr/local/apache2/modules/has libphp5.so, then check httpd.conf for LoadModule libphp5.so

(3) See if there are AddType application/x-httpd-php in httpd.conf. php

(4) Apache must restart the service


12. How to configure Apache virtual host

Vim httpd.conf

#Include conf/extra/httpd-vhosts.conf

Remove the first # of the line and modify it:

<directory/> Options followsymlinks allowoverride None Order deny,allow deny from all</directory> Change to <directory/> Options followsymlinks allowoverride None Order deny,allow allow from all</directory& Gt

Re-vim conf/extra/httpd-vhosts.conf modified according to actual needs


13. How to configure user authentication for Apache

VI httpd.conf

In the corresponding virtual host configuration file segment, add

<directory *> allowoverride authconfig authname "Custom" AuthType Basic Au THUSERFILE/DATA/.HTPASSWD//This directory you can write a random, no restrictions require valid-user</directory>

After saving, then create an Apache authenticated user htpasswd-c/data/.htpasswd test


14. How to configure Apache logs and logs by day cutting

In httpd.conf in the corresponding virtual Host configuration section, add

Customlog "|/usr/local/apache2/bin/rotatelogs-l/usr/local/apache2/logs/www.yourdomain.com-access_%y%m%d.log 86400 "combined

Note that the absolute path needs to be written as a relative path may not take effect


15. How to configure the expiration time for static files such as Apache pictures

Join in httpd.conf

<ifmodule mod_expires.c> expiresactive on Expiresbytype image/gif "Access plus 1 days" expiresbytype image     /jpeg "Access plus hours" expiresbytype image/png "Access plus hours" Expiresbytype text/css "now plus 2 hour" Expiresbytype Application/x-javascript "now plus 2 hours" Expiresbytype Application/x-shockwave-flash "now plus 2 h Ours "ExpiresDefault" now plus 0 min "</IfModule>


16. How to qualify PHP files in a directory without Execute permissions

Vim httpd.conf in the relevant virtual host segment, add

<Directory/www/htdocs/path> Php_admin_flag engine off</directory> where/www/htdocs/path is the directory to restrict


17. How to configure the Apache domain redirection

To forward the domain name www.domain1.com access to www.domain2.com

Realize:

Add <ifmodule mod_rewrite.c> rewriteengine on Rewritecond%{http_host} to the associated virtual host ^www.domain1.com$ Rewriterule ^ (. *) $ http://www.domain2.com/$1 [r=301,l] </IfModule> If multiple domain names are redirected to a domain <ifmodule Mod_rewrit E.c> rewriteengine on Rewritecond%{http_host} ^www.domain.com[or] Rewritecond%{http_host} ^www.d omain1.com$ rewriterule ^ (. *) $ http://www.domain2.com/$1 [r=301,l] </IfModule>


18. How to configure the PHP error log

Vim php.ini Check and configure the following two items

Log_errors = On

Error_log = Logs/error.log


19. How can I configure Open_basedir in PHP to configure Open_basedir for a virtual host in httpd.conf?

Vim php.ini

Join open_basedir=/var/www/

Openbasedir can also be restricted for virtual hosts in httpd.conf:

In the corresponding virtual host configuration file, add:

Php_admin_value Open_basedir "/var/www/htdocs"


20. How to disable the function exec for PHP

Vim PHP.ini found

Disable_functions =

Switch

Disable_functions = EXEC If it is more than one function, you can continue to add the function name separated by commas after exec


21. When we install the lamp environment by source, which one is installed, and which is installed after? Why is it?

Installation order can be MySQL Apache PHP can also be Apache MySQL PHP

Put PHP in the end, this is because when you install PHP, you need to specify the MySQL installation directory, you also need to specify the Apache APXS tool


22. How do you determine which directory your php.ini is in?

Php-i |grep ' Configuration File ' or usr/local/php/bin/php-i |head


23. How to determine where your PHP Extension_dir is?

Php-i |grep ' Extension_dir '


Day 43rd: Questions related to Apache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.