Ubuntu under Nginx installation, basic configuration and common commands

Source: Internet
Author: User

1 Installation:

sudo apt-get install Nginx

2 Start the service:

sudo service nginx start

Or

Sudo/etc/init.d/nginx start

Nginx 80 port forwarding is set by default and can be accessed in the browser after startup http://localhost Check whether the startup was successful.


3 Configuration

Default configuration file:/etc/nginx/nginx.conf

There are two lines in the configuration file that are used to load the external configuration file, as follows:

include/etc/nginx/conf.d/*.conf;include/etc/nginx/sites-enabled/*;

There is a default file under/etc/nginx/sites-enabled/in the second line, and Nginx's proxy configuration is in this area. Content such as:

The following are streamlined:

server {Listen Default_server;listen [::]:80 default_server;root/var/www/html;index index.html index.htm Index.nginx-debian.html;server_name localhost;location/{# First attempt to serve request as file, then# as directory, th En fall back to displaying a 404.try_files $uri $uri/= 404;}}

Create a new nginx configuration file for your project under the/etc/nginx/conf.d/path: myproject.conf, the name can be arbitrarily taken, and then the streamlined part of the code to copy over, according to their own project to do the corresponding configuration, as follows:

server{listen 80;   access_log  /var/log/nginx/myproject.log;    error_log   /var/log/nginx/myproject.log;proxy_ignore_client_abort on;charset utf-8; location ~^\/upload\/* {        root /var;         expires 30d;    }location /          {   proxy_cookie_path /myproject/ /;                 proxy_set_header  Host  $host;                 proxy_set_header X-Real-Ip  $remote _addr;                 proxy_set_header X-Forwarded-For  $remote _addr;                 proxy_pass http://localhost:8080/;           }   }

The main configuration parameters have the following meanings:

(Leave a pit, tomorrow to write ~~~~~~~~~~~~~)



4 after modifying the configuration reload:

sudo nginx-s reload



Reference:

http://oilbeater.com/nginx/2014/12/29/nginx-conf-from-zero.html

http://www.cyberciti.biz/faq/nginx-restart-ubuntu-linux-command/



Ubuntu under Nginx installation, basic configuration and common commands

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.