nginx配置小记

今天搞一哈nginx,nginx的安装很简单就不在赘述了. 主要是我在配置server时遇到一些问题在此记录下来. 给自己提个醒当然能帮助到人那是最好不过的.

首先,nginx的配置文件对内容格式是有要求的. 所以当你从别的地方复制你的server等配置时需要注意空格等字符串问题. 我的是在windows安装的所以还要注意下你配置的静态文件的目录格式:linux的格式为/xxx/xxxx/xxxx/ windows格式:盘符:xxxxx/xxxx/xxx/(千万别直接复制文件路径,因为windows和linux的路径不一致)

另外在nginx安装目录下有一个error.log文件当你发现你的nginx启动后不能访问成功(感觉这里比较坑,启动成功与否需要请求下才行~无语). 说明什么呢?就是报错了呗. 我们就可以去查看log.当然,大家不要去细看我的log. 对你没有意义. 只是贴在这给人一个直观的印象,日志就是这样的. 

2019/06/24 19:17:10 [error] 8568#5020: *3 CreateFile() "G:\develop\nginx\nginx-1.14.0/html/favicon.ico" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2019/06/24 19:28:20 [emerg] 13736#23012: unknown directive "listen       8180" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:31:14 [emerg] 13388#15088: unknown directive "listen       8180" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:31:14 [alert] 22336#8980: worker process 13388 exited with code 1
2019/06/24 19:31:14 [alert] 22336#8980: could not respawn worker
2019/06/24 19:32:12 [emerg] 23340#128: unknown directive "listen       8180" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:35:38 [emerg] 6944#16048: unknown directive "listen       8180" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:38:06 [emerg] 11048#13436: unknown directive "listen       8180" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:39:10 [emerg] 21272#7696: unknown directive "listen       8180" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:43:28 [emerg] 11656#19216: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:44:50 [emerg] 10036#17568: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:46:18 [emerg] 5848#21272: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:46:57 [emerg] 23532#20028: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:48:45 [emerg] 14852#11280: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:57:01 [emerg] 13388#22940: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 19:57:38 [emerg] 15652#8132: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:96
2019/06/24 20:00:10 [emerg] 4388#18908: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:51
2019/06/24 20:00:10 [alert] 11044#12672: worker process 4388 exited with code 1
2019/06/24 20:00:10 [alert] 11044#12672: could not respawn worker
2019/06/24 20:00:16 [emerg] 23008#23280: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:51
2019/06/24 20:01:46 [emerg] 5080#22628: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:95
2019/06/24 20:05:42 [emerg] 15696#23000: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:81
2019/06/25 07:37:30 [emerg] 23052#17496: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:38:33 [emerg] 14324#7356: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:43:30 [emerg] 9684#2960: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:43:51 [emerg] 13044#1276: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:43:53 [emerg] 1824#10720: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:43:54 [emerg] 13664#14316: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:44:00 [emerg] 6244#17972: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:49:15 [emerg] 452#18824: unexpected ";" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:79
2019/06/25 07:50:21 [emerg] 6796#19152: unknown directive " " in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:37
2019/06/25 07:50:45 [emerg] 17656#9792: unknown directive " " in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:37
2019/06/25 07:51:33 [emerg] 10208#12792: unknown directive "location / " in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:40
2019/06/25 07:52:28 [emerg] 20176#21008: invalid number of arguments in "alias" directive in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:42
2019/06/25 07:53:49 [emerg] 14704#13872: invalid number of arguments in "alias" directive in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:42

那个例子:

2019/06/25 07:53:49 [emerg] 14704#13872: invalid number of arguments in "alias" directive in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:42
这是最后一行:意思就是在alias指令中存在非法字符. 这就是我前边所说的路径的格式错误的导致.

所以大家如果真的遇到发现不了的问题源头建议看下这个文件,兴许就迎刃而解了;

另外把我的server贴下,以备不时之需;

	server{ 
		listen       80;
		server_name www.shuguo.com;
		#ssi on;
		#ssi_silent_errors on;
		location / {
			alias D:/projectes/xc-ui-pc-static-portal/;
			index index.html;
		}
	}

注:在配置是每行前边都是tab别用空格,会报错;

例:listen前边都是tab如果改成空格会报:unknown directive "listen 80 不能识别的指令

2019/06/24 20:00:16 [emerg] 23008#23280: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:51
2019/06/24 20:01:46 [emerg] 5080#22628: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:95
2019/06/24 20:05:42 [emerg] 15696#23000: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:81
2019/06/25 07:37:30 [emerg] 23052#17496: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:38:33 [emerg] 14324#7356: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:43:30 [emerg] 9684#2960: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:43:51 [emerg] 13044#1276: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:43:53 [emerg] 1824#10720: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:43:54 [emerg] 13664#14316: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82
2019/06/25 07:44:00 [emerg] 6244#17972: unknown directive "listen       80" in G:\develop\nginx\nginx-1.14.0/conf/nginx.conf:82

 

你可能感兴趣的:(工具安装)