首先先上如何彻底删除nginx

看到这个标题的小伙伴都惊呆了,还不知道怎么搞,却叫我怎么卸载。为什么我要这样,其实,Reset也是一种解决问题的方式嘛。

首先执行下卸载命令

sudo apt-get --purge remove nginx
sudo apt-get autoremove
dpkg --get-selections | grep nginx
sudo apt-get --purge remove nginx-common

这样呢,就卸载了nginx包括配置文件了

在看看进程,执行

root@localhost:~# ps -ef | grep  nginx
root 3729 1 0 04:40 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 3731 3729 0 04:40 ? 00:00:00 nginx: worker process
root 4090 4041 0 05:40 pts/0 00:00:00 grep --color=auto nginx

干掉进程:

sudo kill nginx

查看残余文件

sudo find / -name nginx*
root@localhost:~# sudo find / -name nginx*
/sys/fs/cgroup/systemd/system.slice/nginx.service
/usr/sbin/nginx
/usr/share/doc/nginx-core
/usr/share/doc/nginx-common
/usr/share/doc/nginx
/usr/share/nginx
/usr/share/vim/addons/indent/nginx.vim
/usr/share/vim/addons/syntax/nginx.vim

手动删除文件

sudo rm -r /usr/.....

好了,现在干净了

安装 nginx

sudo apt-get install nginx

查看 nginx 版本

nginx -v #查看详细 nginx -V

启动nginx

sudo /etc/init.d/nginx start

接下来访问:http://localhost 就可以看到nginx的欢迎页面了

Nginx 配置

nginx配置文件位置是 /etc/nginx/nginx.conf默认是下面这样的:


root@localhost:~# vi /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid; events {
worker_connections 768;
# multi_accept on;
} http { ##
# 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_disable "msie6"; # 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;
# }
#}

重点是这个 include /etc/nginx/conf.d/.conf;include /etc/nginx/sites-enabled/;

这样呢,就可以在conf.d文件夹下建立我们自己的配置了,下面是个栗子!

root@localhost:~# cd /etc/nginx/conf.d/
root@localhost:/etc/nginx/conf.d# ls
blog.voidoop.com.conf www.voidoop.com.conf

我这里配置了两个域名的转发规则,以首页www.voidoop.com为例:

server
{
listen 80;
server_name www.voidoop.com; location /
{
proxy_set_header Host $http_host;
proxy_set_header X-Forward-For $remote_addr;
proxy_pass http://www.voidoop.com:3000;
} location ~ .*\.(gif|jpg|js|css|html)$
{
root /var/www/hello/public/;
expires 30d;
}
}

因为 express的默认端口是3000,所以,不想去改变他,就用nginx转发。

修改配置之后,重启nginx

/etc/init.d/nginx restart

最后叨叨location的匹配规则

(1)= 前缀的指令严格匹配这个查询。如果找到,停止搜索。

(2)剩下的常规字符串,最长的匹配优先使用。如果这个匹配使用 ^~ 前缀,搜索停止。

(3)正则表达式,按配置文件里的顺序,第一个匹配的被使用。

(4)如果第三步产生匹配,则使用这个结果。否则使用第二步的匹配结果。

在location中可以使用常规字符串和正则表达式。

如果使用正则表达式,你必须使用以下规则:

   (1)~* 前缀选择不区分大小写的匹配

   (2)~  选择区分大小写的匹配

一切不注明转载源都是耍流氓: http://zhutty.cnblogs.com

[原创]# 玩转nginx系列的更多相关文章

  1. [Linux] PHP程序员玩转Linux系列-nginx初学者引导

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...

  2. [Linux] PHP程序员玩转Linux系列-Linux和Windows安装nginx

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...

  3. [Linux] PHP程序员玩转Linux系列-Nginx中的HTTPS

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...

  4. [Linux] PHP程序员玩转Linux系列-lnmp环境的搭建

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 在平常的工作中,我作为PHP程序员经常要搭建一下环境,这个环境就是Linux系统下安装nginx,php,mysql这三个软件,对软件进行 ...

  5. [Linux] PHP程序员玩转Linux系列-使用supervisor实现守护进程

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...

  6. [Linux] PHP程序员玩转Linux系列-telnet轻松使用邮箱

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...

  7. [Linux] PHP程序员玩转Linux系列-升级PHP到PHP7

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...

  8. [Linux] PHP程序员玩转Linux系列-腾讯云硬盘扩容挂载

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...

  9. [Linux] PHP程序员玩转Linux系列-Ubuntu配置SVN服务器并搭配域名

    在线上部署网站的时候,大部分人是使用ftp,这样的方式很不方便,现在我要在线上安装上SVN的服务器,直接使用svn部署网站.因为搜盘子的服务器是ubuntu,因此下面的步骤是基于ubuntu的. 安装 ...

随机推荐

  1. hdu 2186

    #include <iostream> using namespace std; int main() { int a,b,c,k1,k2,k3,m,n; cin>>m; wh ...

  2. 《node.js开发指南》读书笔记(一)

    在开发时如果修改了js内容,不能通过刷新浏览器直接看到效果,必须通过重启nodejs程序才能看到,这样显然不利于开发调试,supervisor可以实现这个功能,监视对代码的改动,并自动重启nodejs ...

  3. Java Criteria表关联查询(两个表未定义关联关系)

    Criteria criteria = this.getSession().createCriteria(Competition.class, "b"); DetachedCrit ...

  4. javascript判断浏览器

    function getExplorer() { //IE if (navigator.userAgent.indexOf("MSIE")>=0) { } //Firefox ...

  5. 客户端JavaScript(window、document、element)

    一.window对象是所有客户端JavaScript特性和API的主要接入点,用window来引用它. 属性:location属性(引用Location对象,当前显示在窗口的URL).document ...

  6. 动态脚本,在js里面又写js

    不知道怎么回事 代码测试不过 var a=document.createElement("script"); a.type="text/javascript"; ...

  7. 拿起cl.exe,放下IDE

    笔者在这里介绍一种使用cl.exe编译源文件的方法,可以手动执行编译过程而不再依赖IDE,此外,笔者还介绍一些使用cl.exe编译简单源代码的方式. cl.exe是windows平台下的编译连接程序, ...

  8. CentOS+nginx+uwsgi+Python 多站点环境搭建

    转载:http://www.cnblogs.com/xiongpq/p/3381069.html 环境: CentOS X64 6.5 nginx 1.5.6 Python 2.7.5 正文: 一:安 ...

  9. JavaScript 禁用键盘按钮

    代码写多了,有些使用过的方法和技巧会一时半会想不起来,平日记录下来,方便自己和有需要的人日后查阅. $(document).keydown(function () { if (window.event ...

  10. PHP学习系列(1)——字符串处理函数(4)

    16.hebrevc() 函数把希伯来文本从右至左的流转换为左至右的流.它也会把新行 (\n) 转换为 <br />.只有 224 至 251 之间的 ASCII 字符,以及标点符号受到影 ...