Centos server lamp port configuration

Source: Internet
Author: User

Modify the configuration file of Apache in Linux and edit/etc/httpd. conf. The # sign is a comment. It is a sample or description for you and will not be actually executed.

Generally, the default value is listen 80, indicating listening for all non-specific requests on all port 80;
If a row of listen 800 is added, all non-specific requests listening to port 800 are added;
If a listen IP or domain name: 801 is added, port 801 is listened to, but only the access request of the domain name or IP address is responded.

In addition, you can add the virtual host option. The virtual host can be based on different IP addresses (one server can bind multiple IP addresses), different ports, and different host names (domain names ).
If multiple IP addresses exist, you can set multiple virtual machines on the same host based on different IP addresses;
For individual users, the ISP usually has only one public IP address, so multiple virtual machines can be added through different ports;
For website operators, in order to save IP addresses, the port cannot be changed (only 80 can be used). Therefore, domain name-based virtual hosts are usually used.

1. Example of a port-based VM:
The default host is generally placed on port 80 of DocumentRoot "/var/www/html" and listen.
Now I need to add a listener for port 800 for all domain names, so add a line:
Listen 800.
The configurations of the VM corresponding to port 800 are as follows:
<Virtualhost *: 800>
Serveradmin webmaster@dummy-host.com # site master email address
DocumentRoot/var/www/web1 # define the root directory of the website and store the webpage under this directory
Errorlog logs/dummy-host.com-error_log # error logs are stored here
Customlog logs/dummy-host.com-access_log common # customer log
</Virtualhost>
After the configuration is complete, run/etc/rc. d/init. d/httpd restart and enter localhost: 800 in the browser to view the content of the virtual host on the port.

2. The domain name-based virtual host and port-based virtual machine configuration formats are similar, but multiple name-based virtual machines must be defined under the same port, when adding a port listener, the host domain name is configured for one more server name:
Listen Domain Name: port number, for example, listen baby.vicp.net: 80
<Virtualhost *: 80>
Serveradmin webmaster@abc.com # site master email address
DocumentRoot/var/www/web2 # define the root directory of the website
Servername baby.vicp.net # enter the server Domain Name
Errorlog logs/baby.vicp.net-error_log # The error log is stored in
Customlog logs/baby.vicp.net-access_log common # customer log
</Virtualhost>
After the configuration is complete, run/etc/rc. d/init. d/httpd restart, and enter baby.vicp.net in the browser to view the content of the Virtual Host of the domain name. If you want to log on to the Internet, you must configure dynamic domain name software or a Domain Name Server to direct the domain name to the IP address of the local machine.

3. After configuring the port, you need to open it in the firewall

#/Sbin/iptables-I input-P TCP -- dport 800-J accept
#/Sbin/iptables-I input-P TCP -- dport 801-J accept

Then save:
#/Etc/rc. d/init. d/iptables save

Restart service
#/Etc/init. d/iptables restart

The firewall has opened ports 800 and 801 by default, so that the Internet can access the application through IP + port.

Close the firewall and close its services:

View Firewall Information:
#/Etc/init. d/iptables status

Disable the Firewall Service:
#/Etc/init. d/iptables stop

Permanently close? I don't know how to use the permanent method:
# Chkconfig-level 35 iptables off

View IP port status
#/Etc/init. d/iptables status

 

This was transferred from Bory's other blog, and I forgot whether I wrote it myself or reposted it to others. It is marked as original, which may be inaccurate. If you see the original image, Pat (Thank you very much for your original image). Thank you!

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.