Nginx installation configuration

Source: Internet
Author: User
: This article mainly introduces the installation and configuration of nginx. if you are interested in the PHP Tutorial, refer to it.

Nginx installation configuration

1. check whether nginx is installed on the local machine. run the following command:

# Service nginx status

# Which nginx

# Whereis nginx

# Find/-name "* nginx *"

# Rpm-qa | grep nginx

2. generally, run the following command to install yum:

# Yum install nginx

If the nginx repository is successfully configured, the nginx Repository source address cannot be successfully linked. The solution is as follows:

Create the nginx. repo file under/etc/yum. repos. d. The content of the file is as follows:

[Nginx]
Name = nginx repo
Baseurl = http://nginx.org/packages/centos/?releasever/?basearch/
Gpgcheck = 0
Enabled = 1
To use yum for installation again, follow these steps:

# Yum install nginx-y

The default nginx installation address of yum is/etc/nginx.

3. configure the nginx file

A. modify the/etc/nginx. conf file.

Add the content include/etc/nginx/conf. d/demo_nginx.cnf in the last line of http;

B. create the demo_nginx.cnf file under/etc/nginx/conf. d/. the file content is as follows:

# Server load balancer
Upstream demoApp {
Server 10.10.10.40: 8001;
Server 10.10.10.40: 8011;
}
# Set virtual hosts
Server {
Listen 80;
Server_name 10.10.10.40;
Root html;
Location /{
Proxy_redirect off;
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_pass http: // demoApp;
}

# Dynamic requests must go through tomcat
Location ~ . * \. (Jsp | action) $ {
Proxy_set_header Host $ host;
Proxy_set_header X-Forwarded-For $ remote_addr;
Proxy_pass http: // demoApp;
}

Location ~ . * \. (Gif | jpg | jpeg | png | bmp | js | css | html) $ {
Root/u01/demo/project/demoAppResourceHome;
Expires 1d;
}

Location ~ ^/(WEB-INF )/{
Deny all;
}

Error_page 500 502 503 x.html;
Location =/50x.html {
Root/usr/share/nginx/html;
}

Access_log/var/log/nginx/app.demo.com _ access. log;
}

4. start nginx with the following command:

# Service nginx start

If the startup is successful, check the error log for analysis. this is generally because the configuration file is faulty!

Error log Directory:/var/log/nginx/error. log

The above introduces the installation and configuration of nginx, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.

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.