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