Installing and configuring Nginx on Ubuntu/centos System

Source: Internet
Author: User

First, online installation:

Ubuntu:sudo Apt-get Install Nginx

Centos:sudo Yum Install Nginx

Second, the location after installation:

 1.  Service Address:/etc/init.d/nginx 

2, configuration address:/etc/nginx/ :/etc/nginx/nginx.conf

    

3.Web default directory:/usr/share/nginx/http/ : usr/share/nginx/index.html

    

4, log directory:/var/log/nginx/ such as:/var/log/nginx/access.log

    

  5. Main program file:/usr/sbin/nginx

Second, configure the website:

  1, simple Introduction to the function of the configuration file:

First you use the Cd/etc/nginx command to open to Nginx's main configuration directory and then call ll or LS to list the directories.

    

2, for example, I want to configure the following two sites:

(1) Access a website that is stored in the disk location via http://localhost:8080/:/var/www/html/.

(2) Access a website that is stored in the disk location via http://localhost:80/:/var/www/myweb/.

Implementation process:

(1) Open the CD to the/etc/nginx/sites-available directory and use the sudo vim./default to modify the default configuration file under this directory:

Modify the configuration information to the following:

server { Listen 8080 Default_server; Listen [::]:8080 Default_server; # SSL Configuration # # Listen443SSL Default_server; # Listen [::]:443SSL Default_server; Root /var/www/ html; # Home Configurationindex index.html index.htm index.nginx-debian.html;        server_name _; Location/{try_files $uri $uri/ =404; }}server { listen 80; Listen [::]:80;      server_name myweb; Root /var/www/ MyWeb;        Index index.html; Location/{try_files $uri $uri/ =404; }}

      

(2), Save the configuration file: Press Ecs to exit the edit status. shift+: When the command line appears, enter wq! to save. If the hint is that a read-only file cannot be saved, just use the sudo command to re-edit a previous step VI.

Third, start the service:

Input command: sudo systemctl restart Nginx.service

Or:sudo service nginx restart

Start.

      

Iv. Access Test results:

1, if you want to let the outside network access, need to shut down the firewall. Method: sudo iptables-f

2. Effect:

Test port 8080:

Test Port 80:

  

  

  

Installing and configuring Nginx on Ubuntu/centos System

Related Article

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.