标签 Nginx 下的文章

在Typecho服务器启用地址重写时,启用失败。
原因是Nginx服务器默认没有开启地址重写功能
解决方法:
在Nginx的配置文件的server中,加入:

if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;

}

进入网站后台设置-永久链接-开启地址重写功能,然后点击保存设置
进入宝塔面板,设置网站伪静态-加入以下配置后,点击保存-LAMP代码
LNMP代码

直接yum安装即可

yum install nginx -y
配置文件位于:/etc/nginx/nginx.conf,里面可以修改处理器数量、日志路径、pid文件路径等,默认的日志:

错误日志 /var/log/nginx/error.log
访问日志 /var/log/nginx/access.log
在nginx.conf末尾有一句:include /etc/nginx/conf.d/*.conf;  推荐把用户自己的配置放到conf.d/

下面把默认的server修改为一个简单的文件服务器,vi /etc/nginx/conf.d/default.conf,修改监听端口listen和文件目录root

server {
listen 80;
server_name cloud.mrlong.cc; # 自己PC的ip或者服务器的域名
charset utf-8; # 避免中文乱码
root /usr/share/nginx/; # 存放文件的目录
location / {
autoindex on; # 索引
autoindex_exact_size on; # 显示文件大小
autoindex_localtime on; # 显示文件时间
}
}

启动nginx

/etc/init.d/nginx restart

浏览器访问,http://ip+域名,可以看到默认目录下的文件,点击可下载:nginx搭建简单的文件目录服务器 - 第1张  | Mr.Long nginx搭建简单的文件目录服务器 - 第2张  | Mr.Long

另,修改了nginx配置后可以在不影响使用的情况下重载

/etc/init.d/nginx reload

如果碰到
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

我们这么操作:
# sudo sed -i “s/mirrorlist=https/mirrorlist=http/” /etc/yum.repos.d/epel.repo

# yum update

#安装nginx

sudo apt-get install nginx

# 测试nginx安装成功,假设IP为 8.8.8.8

# 浏览器访问 http://8.8.8.8 确认看到 Welcom to nginx!

Nginx配置

/etc/nginx/conf.d/default.conf

server {

    listen 80 default_server;

    listen [::]:80 default_server ipv6only=on;

    

    # 如果要支持HTTPS,修改这里

    # 可以使用 https://letsencrypt.org 的免费SSL证书

    #listen 443 ssl;

    #ssl_certificate     www.example.com.crt;

    #ssl_certificate_key www.example.com.key;

    #ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;

    #ssl_ciphers         HIGH:!aNULL:!MD5;

    

    # 重定向所有HTTP到HTTPS

# rewrite ^(.*)$ https://$host$1 permanent;

 

# 网站根目录,根据需要修改

    root /usr/share/nginx/html;

    # 增加index.php

    index index.php index.html index.htm;

 

# 假设域名是 ssl.mcxiaoke.com

    server_name ssl.mcxiaoke.com; #绑定域名

 

    location / {

        try_files $uri $uri/ =404;

    }

 

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;

    location = /50x.html {

        root /usr/share/nginx/html;

    }

 

#支持php-fpm的配置

    location ~ \.php$ {

        try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:/var/run/php5-fpm.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params;

    }

}

配置完成后,测试一下

# 重启nginx服务

sudo service nginx restart

  • 先执行一下命令:

sudo apt-get --purge remove nginx

sudo apt-get autoremove

dpkg --get -selections|grep nginx

罗列出与nginx相关的软件, nginx-common deinstall 然后

sudo apt-get --purge remove nginx-common

这样就可以完全卸载掉nginx包括配置文件

  • ps -ef |grep nginx 看下nginx还有没有启动,一般执行完1后,nginx还是启动着的,如下:

ps -ef |grep nginx

root 4061 2418 0 Mar11 ? 00:00:00 nginx: master process sbin/nginx

nobody 4062 4061 0 Mar11 ? 00:00:00 nginx: worker process

bkxmgx 15487 4229 0 01:13 pts/0 00:00:00 grep --color=auto nginx

  • kill nginx进程

sudo kill -9 4061 4062

  •  

sudo find / -name nginx*

/usr/local/src/nginx-1.7.9

/usr/local/src/nginx-1.7.9

/objs/src/core/nginx.o

/usr/local/src/nginx-1.7.9/objs/nginx.8

/usr/local/src/nginx-1.7.9/objs/nginx

/usr/local/src/nginx-1.7.9/src/http/modules/perl/nginx.xs

/usr/local/src/nginx-1.7.9/src/http/modules/perl/nginx.pm

/usr/local/src/nginx-1.7.9/src/core/nginx.c

/usr/local/src/nginx-1.7.9/src/core/nginx.h

/usr/local/src/nginx-1.7.9/man/nginx.8

/usr/local/src/nginx-1.7.9/conf/nginx.conf

/usr/local/src/nginx-1.7.9/contrib/vim/syntax/nginx.vim

/usr/local/src/nginx-1.7.9/contrib/vim/ftdetect/nginx.vim

/usr/local/src/nginx-1.7.9/contrib/vim/indent/nginx.vim

/usr/local/nginx /usr/local/nginx/logs/nginx.pid

/usr/local/nginx/conf/nginx.conf.default

/usr/local/nginx/conf/nginx.conf

/usr/local/nginx/sbin/nginx /home/bkxmgx/nginx.conf

golang hugo markdown caddy nginx freebsd

https://golang.org/doc/install 

http://gohugo.io/overview/installing/

go build -o hugo main.go

export GOROOT=$HOME/go

export PATH=$PATH:$GOROOT/bin
hugo version
hugo new site u.zhaoweifeng.cn
mkdir themes
cd themes
git clone https://github.com/spf13/hyde.git
cd ..

vi config.toml