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