配置文件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;
#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
server {
listen 443 ssl;
server_name www.baidu.com;#自己的域名
ssl on;
ssl_certificate /root/ssl/1_www.jianyuejizhang.xyz_bundle.crt;#自己的证书路劲
ssl_certificate_key /root/ssl/2_www.jianyuejizhang.xyz.key;#自己的证书路劲
location / {
proxy_pass http://127.0.0.1:8012;
}
}
}
#查看ngixn版本极其编译参数
/usr/local/nginx/sbin/nginx -V
正常如果没配置的话是没有--with-http_ssl_module的,需要重新编译nginx源码
进入nginx源码目录
cd /root/nginx-1.13.4/
#添加编译模块(上面nginx -v 的configure arguments后面原本有的参数要加上)
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make(make完不要make install,只是编译,不覆盖安装)
#备份nginx的二进制文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
#覆盖nginx的二进制文件
cp objs/nginx /usr/local/nginx/sbin/
如果遇到cannot create regular file '/usr/local/nginx/sbin/nginx': Text file busy
用cp -rfp objs/nginx /usr/local/nginx/sbin/nginx
#测试配置文件是否成功
/usr/local/nginx/sbin/nginx -t 提示success配置成功
#重启nginx
/usr/local/nginx/sbin/nginx -s reload
如果失败则查看nginx进程,然后关闭进程,再启动
#查看nginx进程
ps -ef | grep nginx
#关闭nginx进程
kill -9 7612
kill -9 7613
#启动nginx
先切到根目录cd /
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
执行上面的查看进程,查看是否启动成功
我用nodejs写个了接口,监听8012端口