1、nginx配置的路径常放置在
/etc/nginx
2、查看nginx进程,kill主进程才行
ps aux | grep nginx
3、启动
systemctl start nginx.service
4、重启
systemctl restart nginx.service
5、停止
systemctl stop nginx.service
一份可用的nginx配置:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
# pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
error_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 9000;
listen [::]:9000;
server_name gateway_http;
server_tokens off;
access_log /var/log/nginx/access.log main;
# 文件存放的路径应该为'/app/web/game'
location ~ /game {
index index.html;
root /app/web;
}
# 文件存放的路径应该为'/app/web/h5'
location ~ / {
index index.html;
root /app/web/h5;
}
# / 的配置应该放在最后,否则'/game'的访问真是路径会变为‘/app/web/h5/game’
}
}
6、https重定向为http
有必要说下这个故事,有个h5扫码的功能需要在localhost或https环境下才能启动摄像头,但上线后发现https被重定向为http,最后发现是访问地址的问题
https://xxx.com/
会在nginx被重定向为http://xxx.com
直接访问 https://xxx.com
7、尝试自己配置https证书,网上大部分方法不行或者有些步骤不完整,个人经验是生成的证书不对