安装
环境
Ubuntu 18
安装命令,安装完成会自动启动
sudo apt-get update sudo apt-get intall nginx
sudo systemctl status nginx
结果入下
tina@tina:~$sudo systemctl status nginx ● nginx.service - A high performance web server and a reverse proxy Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendo Active: active (running) since Fri 2021-04-09 11:04:13 CST; 29s a Docs: man:nginx(8) Main PID: 31431 (nginx) Tasks: 5 (limit: 4915) CGroup: /system.slice/nginx.service ├─31431 nginx: master process /usr/sbin/nginx -g daemon o ├─31433 nginx: worker process ├─31434 nginx: worker process ├─31442 nginx: worker process └─31443 nginx: worker process 4月 09 11:04:13 tina systemd[1]: Starting A high performance web ser 4月 09 11:04:13 tina systemd[1]: Started A high performance web serv
常用命令
停止Nginx 服务
sudo systemctl stop nginx
开启服务
sudo systemctl start nginx
重启服务
sudo systemctl restart nginx
加载服务(更改配置文件刷新Nginx)
sudo systemctl reload nginx
禁止Nginx服务
sudo systemctl disable nginx
启用Nginx服务
sudo systemctl enable nginx
配置文件
配置文件都在于/etc/nginx
配置文件在/etc/nginx/nginx.conf
配置使用
sudo vim /etc/nginx/nginx.conf
在Http中加入
server { listen 8080; server_name localhost; location / { root /etc/nginx/modules-enabled/dist; #默认访问目录 index index.html; #默认访问文件 try_files $uri $uri/ /index.html; #目录不存在则执行index.html } }
加入成功即可重新加载nginx配置文件
sudo systemctl reload nginx
在浏览器上面输入,啪了一下很快页面就出来了
http://localhost:8080/index.html
完整
user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http { server { listen 80; server_name localhost; location / { root /etc/nginx/modules-enabled/dist; #默认访问目录 index index.html; #默认访问文件 try_files $uri $uri/ /index.html; #目录不存在则执行index.html } } ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } #mail { # # See sample authentication script at:user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http { server { listen 80; server_name localhost; location / { root /etc/nginx/modules-enabled/dist; #默认访问目录 index index.html; #默认访问文件 try_files $uri $uri/ /index.html; #目录不存在则执行index.html } } ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #} # # http://wiki.nginx.org/ImapAuthenticate WithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #}