2014年1月3日 13:52:07
喜欢这样的风格,干货
http://huoding.com/2013/10/23/290
-----------------下边是我自己的经验(windows)-----------------------
启动nginx
f:/nginxserver/nginx/nginx.exe -c f:/nginxserver/nginx/conf/nginx.conf
在windows下启动nginx要在命令行里进入nginx.exe的那个目录里,否则会提示不能创建日志文件(不能简单的改写环境变量)
nginx: [alert] could not open error log file: CreateFile() "logs/error.log" failed (: The system cannot find the path specified)
如果域名比较多的话,在http配置块里添加指令:server_names_hash_bucket_size 64;
nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size:
如果server 配置块儿中的字符集配置指令如果和默认的冲突了,那就会被忽略掉(我设置为utf8,的冲突了)
nginx: [warn] conflicting server name "charset" on 0.0.0.0:, ignored
nginx: [warn] conflicting server name "utf8" on 0.0.0.0:, ignored
server 块中可以指定日志路径和日志格式,如果指定了日志格式(这里是main),就得保证这个日志格式在http块儿中已经被声明定义了
nginx: [emerg] unknown log format "main" in F:\vc9server\nginx\conf\apache.conf:
如果全局中已经定义了日志配置指令,则虚拟机中的会被忽略
nginx: [warn] conflicting server name "access_log" on 0.0.0.0:, ignored
http块儿中的日志格式定义(main为格式名字, 后边的字符串是具体格式)
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
终止nginx
taskkill /F /IM nginx.exe > nul
2019-6-5 10:08:58 星期三
windows 启动脚本:
@echo off rem 启动进程前杀掉已有进程
taskkill /f /im nginx.exe set currentDir=%cd%
cd %currentDir%
cd nginx nginx.exe -v
echo.
echo Start Nginx
rem nginx.exe -c ./conf/nginx.conf -p %currentDir%
nginx.exe -c ./conf/nginx.conf pause
2019-6-5 9:59:53 星期三
反向代理
### http段配置
upstream php56 {
#ip_hash;
server 127.0.0.1:8061;
server 127.0.0.1:8062;
server 127.0.0.1:8063;
server 127.0.0.1:8064;
server 127.0.0.1:8065; } server {
listen 80;
server_name www.proxy.com ;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://php56;
}
} server {
listen 8061;
server_name www.proxy.com; location ~ \.php$ {
root D:\server\code;
fastcgi_buffer_size 512k;
fastcgi_buffers 32 128k;
fastcgi_pass 127.0.0.1:9561;
fastcgi_read_timeout 239;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME
include fastcgi_params;
} } server {
listen 8062;
server_name www.proxy.com; location ~ \.php$ {
root D:\server\code;
fastcgi_buffer_size 512k;
fastcgi_buffers 32 128k;
fastcgi_pass 127.0.0.1:9562;
fastcgi_read_timeout 239;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME
include fastcgi_params;
} } server {
listen 8063;
server_name www.proxy.com; location ~ \.php$ {
root D:\server\code;
fastcgi_buffer_size 512k;
fastcgi_buffers 32 128k;
fastcgi_pass 127.0.0.1:9563;
fastcgi_read_timeout 239;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME
include fastcgi_params;
} } ###php 测试代码 echo '<pre>'; print_r($_SERVER);
//先启动多个PHP进程(php-cgi.exe), 监听多个不同的端口(如上的 9561, 9562...), 修改hosts添加 127.0.0.1 www.proxy.com; 然后浏览器访问 wwww.proxy.com, 多次刷新, 观察打印出来的服务端端口的变化