ubuntu版本:16.04php
// 更新包 sudo apt-get update // 下载安装nginx sudo apt-get install nginx
在命令行中输入:html
sudo nginx -t
窗口显示:nginx
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
在浏览器中输入ip地址:web
sudo service nginx restart
sudo apt-get --purge remove nginx
sudo apt-get autoremove
dpkg --get-selections|grep nginx sudo apt-get --purge remove nginx sudo apt-get --purge remove nginx-common sudo apt-get --purge remove nginx-core
ps -ef |grep nginx sudo kill -9 XXX
最新版本nginx配置是由4个文件构成:apache
conf.d
:用户本身定义的conf配置文件sites-available
:系统默认设置的配置文件sites-enabled
:由sites-available
中的配置文件转换生成nginx.conf
:汇总以上三个配置文件的内容,同时配置咱们所须要的参数在部署须要的web服务时,咱们能够拷贝sites-enabled
中的default
文件到conf.d而且修更名字为**.conf
,而后进行配置ubuntu
server { #服务启动时监听的端口 listen 80 default_server; listen [::]:80 default_server; #服务启动时文件加载的路径 root /var/www/html/wordpress; #默认加载的第一个文件 index index.php index.html index.htm index.nginx-debian.html; #页面访问域名,若是没有域名也能够填写_ server_name www.xiexianbo.xin; location / { #页面加载失败后所跳转的页面 try_files $uri $uri/ =404; } #如下配置只服务于php # 将PHP脚本传递给在127.0.0.1:9000上监听的FastCGI服务器 location ~ \.php$ { include snippets/fastcgi-php.conf; # With php7.0-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.0-fpm.sock; } # 若是Apache的文档为root,则拒绝访问.htaccess文件 location ~ /\.ht { deny all; } }
注意事项:浏览器
React、Vue等因为是单页面应用,因此咱们在刷新的会遇到资源加载不到的错误,这时咱们须要把页面重定向到index.html服务器
try_files $uri /index.html;
nginx如何优化Web服务php7