[原创]# 玩转nginx系列
首先先上如何彻底删除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系列的更多相关文章
- [Linux] PHP程序员玩转Linux系列-nginx初学者引导
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...
- [Linux] PHP程序员玩转Linux系列-Linux和Windows安装nginx
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...
- [Linux] PHP程序员玩转Linux系列-Nginx中的HTTPS
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...
- [Linux] PHP程序员玩转Linux系列-lnmp环境的搭建
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 在平常的工作中,我作为PHP程序员经常要搭建一下环境,这个环境就是Linux系统下安装nginx,php,mysql这三个软件,对软件进行 ...
- [Linux] PHP程序员玩转Linux系列-使用supervisor实现守护进程
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...
- [Linux] PHP程序员玩转Linux系列-telnet轻松使用邮箱
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...
- [Linux] PHP程序员玩转Linux系列-升级PHP到PHP7
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...
- [Linux] PHP程序员玩转Linux系列-腾讯云硬盘扩容挂载
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 4.PHP程序员玩转L ...
- [Linux] PHP程序员玩转Linux系列-Ubuntu配置SVN服务器并搭配域名
在线上部署网站的时候,大部分人是使用ftp,这样的方式很不方便,现在我要在线上安装上SVN的服务器,直接使用svn部署网站.因为搜盘子的服务器是ubuntu,因此下面的步骤是基于ubuntu的. 安装 ...
随机推荐
- HDU 5139数据离线处理
此题可以找到规律f(n) = 1! * 2! *...*n!, 如果直接打表的话,由于n比较大(10000000),所以会超内存,这时候就要用到离线处理数据,就是先把数据存起来,到最后在暴力一遍求解就 ...
- windows下配置两个或多个Tomcat启动的方法
确保window的环境变量中找不到CATALINA_HOME和CATALINA_BASE 修改server.xml,用解压版的tomcat,不要用安装版的. 1.修改http访问端口 conf下的se ...
- javascript基础之自执行函数
1.匿名函数的定义方式 如下 var temp = function(){} 2.自执行函数 (function(){ 内容 }) () 不带参数 (fun ...
- 武汉科技大学ACM:1004: Lake and Island
Problem Description 北园孩子的专属福利来啦~学校从北区宿舍到湖心岛修建了一条通道让北园的同学们可以上去一(kuang)同(xiu)玩(en)耍(ai),这一天,IcY向ahm001 ...
- gui小日历
package MyCal; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; imp ...
- Android导入项目时出现红色感叹号
导入一个新的项目后,丢失android.jar文件 解决方法:在项目名称上单击右键,选择Properties,再选择Android,再在其中选择一个project build target,点击确定之 ...
- Gradle一分钟实现Spring-MVC
前提: 1,已安装JDK 2, 有Intellij IDEA 3, 已安装Gradle 一分钟实现步骤: 1,mkdir Spring-MVC;cd Spring-MVC2,gradle init3, ...
- ios nslog 打印字典为中文
#import <Foundation/Foundation.h> @implementation NSDictionary (Log) - (NSString *)description ...
- linux 添加 $path
# vim /etc/profile在文档最后,添加:export PATH="/usr/local/src/bin:$PATH"保存,退出,然后运行:#source /etc/p ...
- Number对象
<script type="text/javascript"> /* Number对象. 创建Number对象的方式: 方式1: var 变量= new Number( ...