Windows下Nginx的基本使用

来源:互联网 发布:科比巅峰数据 编辑:程序博客网 时间:2024/06/06 01:02

一、常用命令

1、启动:

C:\server\nginx-1.0.2>start nginx或C:\server\nginx-1.0.2>nginx.exe

注:建议使用第一种,第二种会使你的cmd窗口一直处于执行中,不能进行其他命令操作。

2、停止:

C:\server\nginx-1.0.2>nginx.exe -s stop或C:\server\nginx-1.0.2>nginx.exe -s quit

注:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。

3、重新载入Nginx:

C:\server\nginx-1.0.2>nginx.exe -sreload

当配置信息修改,需要重新载入这些配置时使用此命令。

4、重新打开日志文件:

C:\server\nginx-1.0.2>nginx.exe -sreopen

5、查看Nginx版本:

C:\server\nginx-1.0.2>nginx -v

二、配置代码(nginx.conf)

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '    #                  '$status $body_bytes_sent "$http_referer" '    #                  '"$http_user_agent" "$http_x_forwarded_for"';    #access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;#keepalive_timeout 185;    #gzip  on;    #server {    #    listen       80;    #    server_name  localhost;#    #    #charset koi8-r;#    #    #access_log  logs/host.access.log  main;#    #    location / {    #        root   html;    #       index  index.html index.htm;    #    }#    #    #error_page  404              /404.html;#    #    # redirect server error pages to the static page /50x.html    #    #    #    error_page   500 502 503 504  /50x.html;    #    location = /50x.html {    #       root   html;    #   }#        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        #location ~ \.php$ {        #    root           html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;        #    include        fastcgi_params;        #}        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    #}    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}    # HTTPS server    #
  #第一个tomcat
 server {

#监听端口
listen 80; #http
listen 443 ssl; #https

server_name www.sakework.com sakework.com;#请求域名

#证书
ssl_certificate /crte/213958981210450.pem;#证书目录
ssl_certificate_key /crte/213958981210450.key;#证书目录
    #证书 https类型    ssl_protocols       SSLv3 TLSv1.2;        
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://localhost:8080/; #跳转地址
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 1;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
}
}
  #第二个tomcat
server {

listen 80; #http
server_name tongji.sakework.com;#请求域名

location / {
proxy_pass http://localhost:8081/; #跳转地址
proxy_redirect off ;
proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 1;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
}
}
}