How to configure apache and nginx virtual hosts in ubuntu

Source: Internet
Author: User
Tags fully qualified domain name

Apache virtual host configuration

The code is as follows: Copy code

# Creating a directory #
$ Mkdir/var/www/phperstar

# Creating a VM configuration file #
$ Cd/etc/apache2/sites-enabled/
$ Vi websitename

# Copy the content, paste it into the configuration file, save and exit #
<VirtualHost *: 80>
ServerAdmin webmaster @ localhost
ServerName www.111cn.net # change it to the domain name you want to use #
DocumentRoot/var/www/phperstar # directory for storing programs #
<Directory/>
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory/var/www/phperstar> # Directory for storing programs #
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow, deny
Allow from all
</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 $ {APACHE_LOG_DIR}/www.111cn.net _ error. log # error log Directory #

# Possible values include: debug, info, notice, warn, error, crit,
# Alert, emerg.
LogLevel warn

CustomLog $ {APACHE_LOG_DIR}/www.111cn.net _ access. log combined # access log Directory #
</VirtualHost>

# Enable the configuration file #
$ Cd/etc/apache2
$ Sudo a2ensite websitename
Enabling site phperstar.
To activate the new configuration, you need to run:
Service apache2 reload

# Restart apache #
$ Sudo service apache2 reload
Apache2: cocould not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[OK]

# Binding hosts #
$ Vi/etc/hosts

# Add the domain name configured below and save it for release #
127.0.1.1 www.111cn.net

Then the browser accesses the domain name.

Configure the virtual host and directory in ubuntu nginx

In/etc/nginx/sites-available/create www.111cn.net (your dns name) file

The code is as follows: Copy code

Server {
Listen 80; # listen for ipv4; this line is default and implied
# Listen [:]: 80 default ipv6only = on; # listen for ipv6

Root/home/angelmylove/zendphp/MyAngelMyLove/; # absolute path to the directory where your website is located
Index. php index.html index.htm; # directory index

# Make site accessible from http: // localhost/
Server_name www.111cn.net; # domain name of the website

Location /{
Index index.html index.htm index. php; # directory index
Rewrite ^/(. *) $/index. php/$1 last; # Rewrite hide index. php
      }

# Enable nginx to support php
Location ~ ^ (. +. Php) (. *) $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_split_path_info ^ (. +. php) (. *) $;
Fastcgi_param SCRIPT_FILENAME/var/www $ fastcgi_script_name;
   }
}

Add 127.0.0.1 www.111cn.net to The etc/hosts file.

The code is as follows: Copy code

Service php5-fpm restart
Service nginx restart

Note: This configuration may cause file path errors.

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.